Merge pull request #7 from muhammedfurkan/deepsource-fix-0d9e6f69

Change `NotImplemented` to `NotImplementedError`
This commit is contained in:
M.Furkan 2020-11-09 00:40:34 +03:00 committed by GitHub
commit 46e33f9dd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,29 +13,45 @@ from .fields import BaseField
if typing.TYPE_CHECKING:
from ..bot.bot import Bot
__all__ = ('MetaTelegramObject', 'TelegramObject', 'InputFile', 'String', 'Integer', 'Float', 'Boolean')
__all__ = (
"MetaTelegramObject",
"TelegramObject",
"InputFile",
"String",
"Integer",
"Float",
"Boolean",
)
PROPS_ATTR_NAME = '_props'
VALUES_ATTR_NAME = '_values'
ALIASES_ATTR_NAME = '_aliases'
PROPS_ATTR_NAME = "_props"
VALUES_ATTR_NAME = "_values"
ALIASES_ATTR_NAME = "_aliases"
# Binding of builtin types
InputFile = TypeVar('InputFile', 'InputFile', io.BytesIO, io.FileIO, str)
String = TypeVar('String', bound=str)
Integer = TypeVar('Integer', bound=int)
Float = TypeVar('Float', bound=float)
Boolean = TypeVar('Boolean', bound=bool)
T = TypeVar('T')
InputFile = TypeVar("InputFile", "InputFile", io.BytesIO, io.FileIO, str)
String = TypeVar("String", bound=str)
Integer = TypeVar("Integer", bound=int)
Float = TypeVar("Float", bound=float)
Boolean = TypeVar("Boolean", bound=bool)
T = TypeVar("T")
class MetaTelegramObject(type):
"""
Metaclass for telegram objects
"""
_objects = {}
def __new__(mcs: typing.Type[T], name: str, bases: typing.Tuple[typing.Type], namespace: typing.Dict[str, typing.Any], **kwargs: typing.Any) -> T:
cls = super(MetaTelegramObject, mcs).__new__(mcs, name, bases, namespace)
def __new__(
mcs: typing.Type[T],
name: str,
bases: typing.Tuple[typing.Type],
namespace: typing.Dict[str, typing.Any],
**kwargs: typing.Any
) -> T:
cls = super(MetaTelegramObject, mcs).__new__(
mcs, name, bases, namespace)
props = {}
values = {}
@ -50,7 +66,11 @@ class MetaTelegramObject(type):
aliases.update(getattr(base, ALIASES_ATTR_NAME))
# Scan current object for props
for name, prop in ((name, prop) for name, prop in namespace.items() if isinstance(prop, BaseField)):
for name, prop in (
(name, prop)
for name, prop in namespace.items()
if isinstance(prop, BaseField)
):
props[prop.alias] = prop
if prop.default is not None:
values[prop.alias] = prop.default
@ -75,7 +95,9 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
Abstract class for telegram objects
"""
def __init__(self, conf: typing.Dict[str, typing.Any]=None, **kwargs: typing.Any) -> None:
def __init__(
self, conf: typing.Dict[str, typing.Any] = None, **kwargs: typing.Any
) -> None:
"""
Deserialize object
@ -151,9 +173,11 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
bot = Bot.get_current()
if bot is None:
raise RuntimeError("Can't get bot instance from context. "
"You can fix it with setting current instance: "
"'Bot.set_current(bot_instance)'")
raise RuntimeError(
"Can't get bot instance from context. "
"You can fix it with setting current instance: "
"'Bot.set_current(bot_instance)'"
)
return bot
def to_python(self) -> typing.Dict[str, typing.Any]:
@ -194,7 +218,7 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
@classmethod
def create(cls: typing.Type[T], *args: typing.Any, **kwargs: typing.Any) -> T:
raise NotImplemented
raise NotImplementedError
def __str__(self) -> str:
"""
@ -224,7 +248,7 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
:return:
"""
if key in self.props:
return self.props[key].set_value(self, value, self.conf.get('parent', None))
return self.props[key].set_value(self, value, self.conf.get("parent", None))
raise KeyError(key)
def __contains__(self, item: str) -> bool: