mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-06 06:33:10 +03:00
Fix docgen in strict mode
This commit is contained in:
parent
5376905e3d
commit
9e43700f55
|
@ -1,9 +1,33 @@
|
||||||
|
"""
|
||||||
|
Class definitions stolen from `trio`, with some modifications.
|
||||||
|
"""
|
||||||
|
import abc
|
||||||
from typing import Type, TypeVar
|
from typing import Type, TypeVar
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
class NoPublicConstructor(type):
|
class Final(abc.ABCMeta):
|
||||||
|
def __new__(
|
||||||
|
cls,
|
||||||
|
name: str,
|
||||||
|
bases: tuple[type, ...],
|
||||||
|
cls_namespace: dict[str, object],
|
||||||
|
) -> "Final":
|
||||||
|
# Allow subclassing while within telethon._impl (or other package names).
|
||||||
|
allowed_base = Final.__module__[
|
||||||
|
: Final.__module__.find(".", Final.__module__.find(".") + 1)
|
||||||
|
]
|
||||||
|
for base in bases:
|
||||||
|
if isinstance(base, Final) and not base.__module__.startswith(allowed_base):
|
||||||
|
raise TypeError(
|
||||||
|
f"{base.__module__}.{base.__qualname__} does not support"
|
||||||
|
" subclassing"
|
||||||
|
)
|
||||||
|
return super().__new__(cls, name, bases, cls_namespace)
|
||||||
|
|
||||||
|
|
||||||
|
class NoPublicConstructor(Final):
|
||||||
def __call__(cls, *args: object, **kwargs: object) -> None:
|
def __call__(cls, *args: object, **kwargs: object) -> None:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f"{cls.__module__}.{cls.__qualname__} has no public constructor"
|
f"{cls.__module__}.{cls.__qualname__} has no public constructor"
|
||||||
|
|
|
@ -204,7 +204,7 @@ class Encrypted(Mtp):
|
||||||
self._rpc_results.append(
|
self._rpc_results.append(
|
||||||
(
|
(
|
||||||
msg_id,
|
msg_id,
|
||||||
RpcError.from_mtproto_error(GeneratedRpcError.from_bytes(result)),
|
RpcError._from_mtproto_error(GeneratedRpcError.from_bytes(result)),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif inner_constructor == RpcAnswerUnknown.constructor_id():
|
elif inner_constructor == RpcAnswerUnknown.constructor_id():
|
||||||
|
|
|
@ -38,7 +38,7 @@ class RpcError(ValueError):
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_mtproto_error(cls, error: GeneratedRpcError) -> Self:
|
def _from_mtproto_error(cls, error: GeneratedRpcError) -> Self:
|
||||||
if m := re.search(r"-?\d+", error.error_message):
|
if m := re.search(r"-?\d+", error.error_message):
|
||||||
name = re.sub(
|
name = re.sub(
|
||||||
r"_{2,}",
|
r"_{2,}",
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from ._impl.client.client import Config, InlineResult, InlineResults
|
||||||
from ._impl.client.types import (
|
from ._impl.client.types import (
|
||||||
AsyncList,
|
AsyncList,
|
||||||
Channel,
|
Channel,
|
||||||
|
@ -9,15 +10,17 @@ from ._impl.client.types import (
|
||||||
LoginToken,
|
LoginToken,
|
||||||
MediaLike,
|
MediaLike,
|
||||||
Message,
|
Message,
|
||||||
NoPublicConstructor,
|
|
||||||
OutFileLike,
|
OutFileLike,
|
||||||
PasswordToken,
|
PasswordToken,
|
||||||
RestrictionReason,
|
RestrictionReason,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
from ._impl.session import PackedChat
|
from ._impl.session import PackedChat, PackedType
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
"Config",
|
||||||
|
"InlineResult",
|
||||||
|
"InlineResults",
|
||||||
"AsyncList",
|
"AsyncList",
|
||||||
"Channel",
|
"Channel",
|
||||||
"Chat",
|
"Chat",
|
||||||
|
@ -28,10 +31,10 @@ __all__ = [
|
||||||
"LoginToken",
|
"LoginToken",
|
||||||
"MediaLike",
|
"MediaLike",
|
||||||
"Message",
|
"Message",
|
||||||
"NoPublicConstructor",
|
|
||||||
"OutFileLike",
|
"OutFileLike",
|
||||||
"PasswordToken",
|
"PasswordToken",
|
||||||
"RestrictionReason",
|
"RestrictionReason",
|
||||||
"User",
|
"User",
|
||||||
"PackedChat",
|
"PackedChat",
|
||||||
|
"PackedType",
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,7 +7,7 @@ from telethon._impl.tl.mtproto.types import RpcError as GeneratedRpcError
|
||||||
|
|
||||||
|
|
||||||
def test_rpc_error_parsing() -> None:
|
def test_rpc_error_parsing() -> None:
|
||||||
assert RpcError.from_mtproto_error(
|
assert RpcError._from_mtproto_error(
|
||||||
GeneratedRpcError(
|
GeneratedRpcError(
|
||||||
error_code=400,
|
error_code=400,
|
||||||
error_message="CHAT_INVALID",
|
error_message="CHAT_INVALID",
|
||||||
|
@ -19,7 +19,7 @@ def test_rpc_error_parsing() -> None:
|
||||||
caused_by=None,
|
caused_by=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert RpcError.from_mtproto_error(
|
assert RpcError._from_mtproto_error(
|
||||||
GeneratedRpcError(
|
GeneratedRpcError(
|
||||||
error_code=420,
|
error_code=420,
|
||||||
error_message="FLOOD_WAIT_31",
|
error_message="FLOOD_WAIT_31",
|
||||||
|
@ -31,7 +31,7 @@ def test_rpc_error_parsing() -> None:
|
||||||
caused_by=None,
|
caused_by=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert RpcError.from_mtproto_error(
|
assert RpcError._from_mtproto_error(
|
||||||
GeneratedRpcError(
|
GeneratedRpcError(
|
||||||
error_code=500,
|
error_code=500,
|
||||||
error_message="INTERDC_2_CALL_ERROR",
|
error_message="INTERDC_2_CALL_ERROR",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user