Fix docgen in strict mode

This commit is contained in:
Lonami Exo 2023-09-13 20:07:07 +02:00
parent 5376905e3d
commit 9e43700f55
5 changed files with 36 additions and 9 deletions

View File

@ -1,9 +1,33 @@
"""
Class definitions stolen from `trio`, with some modifications.
"""
import abc
from typing import Type, TypeVar
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:
raise TypeError(
f"{cls.__module__}.{cls.__qualname__} has no public constructor"

View File

@ -204,7 +204,7 @@ class Encrypted(Mtp):
self._rpc_results.append(
(
msg_id,
RpcError.from_mtproto_error(GeneratedRpcError.from_bytes(result)),
RpcError._from_mtproto_error(GeneratedRpcError.from_bytes(result)),
)
)
elif inner_constructor == RpcAnswerUnknown.constructor_id():

View File

@ -38,7 +38,7 @@ class RpcError(ValueError):
return self._value
@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):
name = re.sub(
r"_{2,}",

View File

@ -1,3 +1,4 @@
from ._impl.client.client import Config, InlineResult, InlineResults
from ._impl.client.types import (
AsyncList,
Channel,
@ -9,15 +10,17 @@ from ._impl.client.types import (
LoginToken,
MediaLike,
Message,
NoPublicConstructor,
OutFileLike,
PasswordToken,
RestrictionReason,
User,
)
from ._impl.session import PackedChat
from ._impl.session import PackedChat, PackedType
__all__ = [
"Config",
"InlineResult",
"InlineResults",
"AsyncList",
"Channel",
"Chat",
@ -28,10 +31,10 @@ __all__ = [
"LoginToken",
"MediaLike",
"Message",
"NoPublicConstructor",
"OutFileLike",
"PasswordToken",
"RestrictionReason",
"User",
"PackedChat",
"PackedType",
]

View File

@ -7,7 +7,7 @@ from telethon._impl.tl.mtproto.types import RpcError as GeneratedRpcError
def test_rpc_error_parsing() -> None:
assert RpcError.from_mtproto_error(
assert RpcError._from_mtproto_error(
GeneratedRpcError(
error_code=400,
error_message="CHAT_INVALID",
@ -19,7 +19,7 @@ def test_rpc_error_parsing() -> None:
caused_by=None,
)
assert RpcError.from_mtproto_error(
assert RpcError._from_mtproto_error(
GeneratedRpcError(
error_code=420,
error_message="FLOOD_WAIT_31",
@ -31,7 +31,7 @@ def test_rpc_error_parsing() -> None:
caused_by=None,
)
assert RpcError.from_mtproto_error(
assert RpcError._from_mtproto_error(
GeneratedRpcError(
error_code=500,
error_message="INTERDC_2_CALL_ERROR",