mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Merge pull request #6 from muhammedfurkan/deepsource-transform-9c2dff22
Format code with black, autopep8 and isort
This commit is contained in:
commit
bceacb14ff
3 changed files with 98 additions and 67 deletions
|
|
@ -14,26 +14,29 @@ class InlineKeyboardMarkup(base.TelegramObject):
|
|||
|
||||
https://core.telegram.org/bots/api#inlinekeyboardmarkup
|
||||
"""
|
||||
inline_keyboard: 'typing.List[typing.List[InlineKeyboardButton]]' = fields.ListOfLists(base='InlineKeyboardButton')
|
||||
|
||||
inline_keyboard: "typing.List[typing.List[InlineKeyboardButton]]" = (
|
||||
fields.ListOfLists(base="InlineKeyboardButton")
|
||||
)
|
||||
|
||||
def __init__(self, row_width=3, inline_keyboard=None, **kwargs):
|
||||
if inline_keyboard is None:
|
||||
inline_keyboard = []
|
||||
|
||||
conf = kwargs.pop('conf', {}) or {}
|
||||
conf['row_width'] = row_width
|
||||
conf = kwargs.pop("conf", {}) or {}
|
||||
conf["row_width"] = row_width
|
||||
|
||||
super(InlineKeyboardMarkup, self).__init__(**kwargs,
|
||||
conf=conf,
|
||||
inline_keyboard=inline_keyboard)
|
||||
super(InlineKeyboardMarkup, self).__init__(
|
||||
**kwargs, conf=conf, inline_keyboard=inline_keyboard
|
||||
)
|
||||
|
||||
@property
|
||||
def row_width(self):
|
||||
return self.conf.get('row_width', 3)
|
||||
return self.conf.get("row_width", 3)
|
||||
|
||||
@row_width.setter
|
||||
def row_width(self, value):
|
||||
self.conf['row_width'] = value
|
||||
self.conf["row_width"] = value
|
||||
|
||||
def add(self, *args):
|
||||
"""
|
||||
|
|
@ -86,6 +89,7 @@ class InlineKeyboardButton(base.TelegramObject):
|
|||
|
||||
https://core.telegram.org/bots/api#inlinekeyboardbutton
|
||||
"""
|
||||
|
||||
text: base.String = fields.Field()
|
||||
url: base.String = fields.Field()
|
||||
login_url: LoginUrl = fields.Field(base=LoginUrl)
|
||||
|
|
@ -95,19 +99,26 @@ class InlineKeyboardButton(base.TelegramObject):
|
|||
callback_game: CallbackGame = fields.Field(base=CallbackGame)
|
||||
pay: base.Boolean = fields.Field()
|
||||
|
||||
def __init__(self, text: base.String,
|
||||
url: base.String = None,
|
||||
login_url: LoginUrl = None,
|
||||
callback_data: base.String = None,
|
||||
switch_inline_query: base.String = None,
|
||||
switch_inline_query_current_chat: base.String = None,
|
||||
callback_game: CallbackGame = None,
|
||||
pay: base.Boolean = None, **kwargs):
|
||||
super(InlineKeyboardButton, self).__init__(text=text,
|
||||
url=url,
|
||||
login_url=login_url,
|
||||
callback_data=callback_data,
|
||||
switch_inline_query=switch_inline_query,
|
||||
switch_inline_query_current_chat=switch_inline_query_current_chat,
|
||||
callback_game=callback_game,
|
||||
pay=pay, **kwargs)
|
||||
def __init__(
|
||||
self,
|
||||
text: base.String,
|
||||
url: base.String = None,
|
||||
login_url: LoginUrl = None,
|
||||
callback_data: base.String = None,
|
||||
switch_inline_query: base.String = None,
|
||||
switch_inline_query_current_chat: base.String = None,
|
||||
callback_game: CallbackGame = None,
|
||||
pay: base.Boolean = None,
|
||||
**kwargs
|
||||
):
|
||||
super(InlineKeyboardButton, self).__init__(
|
||||
text=text,
|
||||
url=url,
|
||||
login_url=login_url,
|
||||
callback_data=callback_data,
|
||||
switch_inline_query=switch_inline_query,
|
||||
switch_inline_query_current_chat=switch_inline_query_current_chat,
|
||||
callback_game=callback_game,
|
||||
pay=pay,
|
||||
**kwargs
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class KeyboardButtonPollType(base.TelegramObject):
|
|||
|
||||
https://core.telegram.org/bots/api#keyboardbuttonpolltype
|
||||
"""
|
||||
|
||||
type: base.String = fields.Field()
|
||||
|
||||
def __init__(self, type: typing.Optional[base.String] = None):
|
||||
|
|
@ -21,27 +22,37 @@ class ReplyKeyboardMarkup(base.TelegramObject):
|
|||
|
||||
https://core.telegram.org/bots/api#replykeyboardmarkup
|
||||
"""
|
||||
keyboard: 'typing.List[typing.List[KeyboardButton]]' = fields.ListOfLists(base='KeyboardButton', default=[])
|
||||
|
||||
keyboard: "typing.List[typing.List[KeyboardButton]]" = fields.ListOfLists(
|
||||
base="KeyboardButton", default=[]
|
||||
)
|
||||
resize_keyboard: base.Boolean = fields.Field()
|
||||
one_time_keyboard: base.Boolean = fields.Field()
|
||||
selective: base.Boolean = fields.Field()
|
||||
|
||||
def __init__(self, keyboard: 'typing.List[typing.List[KeyboardButton]]' = None,
|
||||
resize_keyboard: base.Boolean = None,
|
||||
one_time_keyboard: base.Boolean = None,
|
||||
selective: base.Boolean = None,
|
||||
row_width: base.Integer = 3):
|
||||
super(ReplyKeyboardMarkup, self).__init__(keyboard=keyboard, resize_keyboard=resize_keyboard,
|
||||
one_time_keyboard=one_time_keyboard, selective=selective,
|
||||
conf={'row_width': row_width})
|
||||
def __init__(
|
||||
self,
|
||||
keyboard: "typing.List[typing.List[KeyboardButton]]" = None,
|
||||
resize_keyboard: base.Boolean = None,
|
||||
one_time_keyboard: base.Boolean = None,
|
||||
selective: base.Boolean = None,
|
||||
row_width: base.Integer = 3,
|
||||
):
|
||||
super(ReplyKeyboardMarkup, self).__init__(
|
||||
keyboard=keyboard,
|
||||
resize_keyboard=resize_keyboard,
|
||||
one_time_keyboard=one_time_keyboard,
|
||||
selective=selective,
|
||||
conf={"row_width": row_width},
|
||||
)
|
||||
|
||||
@property
|
||||
def row_width(self):
|
||||
return self.conf.get('row_width', 3)
|
||||
return self.conf.get("row_width", 3)
|
||||
|
||||
@row_width.setter
|
||||
def row_width(self, value):
|
||||
self.conf['row_width'] = value
|
||||
self.conf["row_width"] = value
|
||||
|
||||
def add(self, *args):
|
||||
"""
|
||||
|
|
@ -100,21 +111,27 @@ class KeyboardButton(base.TelegramObject):
|
|||
|
||||
https://core.telegram.org/bots/api#keyboardbutton
|
||||
"""
|
||||
|
||||
text: base.String = fields.Field()
|
||||
request_contact: base.Boolean = fields.Field()
|
||||
request_location: base.Boolean = fields.Field()
|
||||
request_poll: KeyboardButtonPollType = fields.Field()
|
||||
|
||||
def __init__(self, text: base.String,
|
||||
request_contact: base.Boolean = None,
|
||||
request_location: base.Boolean = None,
|
||||
request_poll: KeyboardButtonPollType = None,
|
||||
**kwargs):
|
||||
super(KeyboardButton, self).__init__(text=text,
|
||||
request_contact=request_contact,
|
||||
request_location=request_location,
|
||||
request_poll=request_poll,
|
||||
**kwargs)
|
||||
def __init__(
|
||||
self,
|
||||
text: base.String,
|
||||
request_contact: base.Boolean = None,
|
||||
request_location: base.Boolean = None,
|
||||
request_poll: KeyboardButtonPollType = None,
|
||||
**kwargs
|
||||
):
|
||||
super(KeyboardButton, self).__init__(
|
||||
text=text,
|
||||
request_contact=request_contact,
|
||||
request_location=request_location,
|
||||
request_poll=request_poll,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
|
||||
class ReplyKeyboardRemove(base.TelegramObject):
|
||||
|
|
@ -123,8 +140,11 @@ class ReplyKeyboardRemove(base.TelegramObject):
|
|||
|
||||
https://core.telegram.org/bots/api#replykeyboardremove
|
||||
"""
|
||||
|
||||
remove_keyboard: base.Boolean = fields.Field(default=True)
|
||||
selective: base.Boolean = fields.Field()
|
||||
|
||||
def __init__(self, selective: base.Boolean = None):
|
||||
super(ReplyKeyboardRemove, self).__init__(remove_keyboard=True, selective=selective)
|
||||
super(ReplyKeyboardRemove, self).__init__(
|
||||
remove_keyboard=True, selective=selective
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ Example:
|
|||
"""
|
||||
from typing import List
|
||||
|
||||
PROPS_KEYS_ATTR_NAME = '_props_keys'
|
||||
PROPS_KEYS_ATTR_NAME = "_props_keys"
|
||||
|
||||
|
||||
class Helper:
|
||||
mode = ''
|
||||
mode = ""
|
||||
|
||||
@classmethod
|
||||
def all(cls):
|
||||
|
|
@ -40,13 +40,13 @@ class Helper:
|
|||
|
||||
|
||||
class HelperMode(Helper):
|
||||
mode = 'original'
|
||||
mode = "original"
|
||||
|
||||
SCREAMING_SNAKE_CASE = 'SCREAMING_SNAKE_CASE'
|
||||
lowerCamelCase = 'lowerCamelCase'
|
||||
CamelCase = 'CamelCase'
|
||||
snake_case = 'snake_case'
|
||||
lowercase = 'lowercase'
|
||||
SCREAMING_SNAKE_CASE = "SCREAMING_SNAKE_CASE"
|
||||
lowerCamelCase = "lowerCamelCase"
|
||||
CamelCase = "CamelCase"
|
||||
snake_case = "snake_case"
|
||||
lowercase = "lowercase"
|
||||
|
||||
@classmethod
|
||||
def all(cls):
|
||||
|
|
@ -68,9 +68,9 @@ class HelperMode(Helper):
|
|||
"""
|
||||
if text.isupper():
|
||||
return text
|
||||
result = ''
|
||||
result = ""
|
||||
for pos, symbol in enumerate(text):
|
||||
result += '_' + symbol if symbol.isupper() and pos > 0 else symbol.upper()
|
||||
result += "_" + symbol if symbol.isupper() and pos > 0 else symbol.upper()
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
|
|
@ -94,10 +94,10 @@ class HelperMode(Helper):
|
|||
:param first_upper: first symbol must be upper?
|
||||
:return:
|
||||
"""
|
||||
result = ''
|
||||
result = ""
|
||||
need_upper = False
|
||||
for pos, symbol in enumerate(text):
|
||||
if symbol == '_' and pos > 0:
|
||||
if symbol == "_" and pos > 0:
|
||||
need_upper = True
|
||||
else:
|
||||
result += symbol.upper() if need_upper else symbol.lower()
|
||||
|
|
@ -120,7 +120,7 @@ class HelperMode(Helper):
|
|||
if mode == cls.snake_case:
|
||||
return cls._snake_case(text)
|
||||
if mode == cls.lowercase:
|
||||
return cls._snake_case(text).replace('_', '')
|
||||
return cls._snake_case(text).replace("_", "")
|
||||
if mode == cls.lowerCamelCase:
|
||||
return cls._camel_case(text)
|
||||
if mode == cls.CamelCase:
|
||||
|
|
@ -146,9 +146,9 @@ class Item:
|
|||
|
||||
def __set_name__(self, owner, name):
|
||||
if not name.isupper():
|
||||
raise NameError('Name for helper item must be in uppercase!')
|
||||
if not self._value and hasattr(owner, 'mode'):
|
||||
self._value = HelperMode.apply(name, getattr(owner, 'mode'))
|
||||
raise NameError("Name for helper item must be in uppercase!")
|
||||
if not self._value and hasattr(owner, "mode"):
|
||||
self._value = HelperMode.apply(name, getattr(owner, "mode"))
|
||||
|
||||
|
||||
class ListItem(Item):
|
||||
|
|
@ -190,16 +190,16 @@ class ItemsList(list):
|
|||
|
||||
|
||||
class OrderedHelperMeta(type):
|
||||
|
||||
def __new__(mcs, name, bases, namespace, **kwargs):
|
||||
cls = super().__new__(mcs, name, bases, namespace)
|
||||
|
||||
props_keys = list((
|
||||
props_keys = list(
|
||||
(
|
||||
name
|
||||
for name, prop in namespace.items()
|
||||
if isinstance(prop, (Item, ListItem))
|
||||
))
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
setattr(cls, PROPS_KEYS_ATTR_NAME, props_keys)
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ class OrderedHelperMeta(type):
|
|||
|
||||
|
||||
class OrderedHelper(metaclass=OrderedHelperMeta):
|
||||
mode = ''
|
||||
mode = ""
|
||||
|
||||
@classmethod
|
||||
def all(cls) -> List[str]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue