Skip to content

Commit cd510a5

Browse files
committed
fix(errors): using wildcard imports to avoid missing error imports
this needs to be done here since Hydrogram errors are generated by our compiler and defining it explicitly would cause errors to be left out of the list.
1 parent 6b0d697 commit cd510a5

2 files changed

Lines changed: 2 additions & 41 deletions

File tree

hydrogram/errors/__init__.py

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,10 @@
1919

2020
from __future__ import annotations
2121

22-
import re
23-
from importlib import import_module
2422
from typing import ClassVar
2523

26-
from .exceptions.all import exceptions
27-
from .exceptions.bad_request_400 import BadRequest
28-
from .exceptions.flood_420 import Flood
29-
from .exceptions.forbidden_403 import Forbidden
30-
from .exceptions.internal_server_error_500 import InternalServerError
31-
from .exceptions.not_acceptable_406 import NotAcceptable
32-
from .exceptions.see_other_303 import SeeOther
33-
from .exceptions.service_unavailable_503 import ServiceUnavailable
34-
from .exceptions.unauthorized_401 import Unauthorized
35-
from .pyromod import ListenerStopped, ListenerTimeout
36-
from .rpc_error import RPCError, UnknownError
24+
from .exceptions import * # noqa: F403
25+
from .rpc_error import UnknownError
3726

3827

3928
class BadMsgNotification(Exception): # noqa: N818
@@ -81,37 +70,10 @@ def __init__(self, msg: str | None = None):
8170
super().__init__("A CDN file hash mismatch has occurred." if msg is None else msg)
8271

8372

84-
error_objects = {}
85-
for error_code, error_dict in exceptions.items():
86-
for error_name, class_name in error_dict.items():
87-
if error_name == "_":
88-
continue
89-
base = re.sub(r"(?<!^)(?=[A-Z])", "_", error_dict["_"]).lower()
90-
module_name = f".exceptions.{base}_{error_code}"
91-
try:
92-
module = import_module(module_name, package="hydrogram.errors")
93-
error_objects[class_name] = getattr(module, class_name)
94-
except (ImportError, AttributeError):
95-
continue
96-
97-
locals().update(error_objects)
98-
9973
__all__ = [
10074
"BadMsgNotification",
101-
"BadRequest",
10275
"CDNFileHashMismatch",
103-
"Flood",
104-
"Forbidden",
105-
"InternalServerError",
106-
"ListenerStopped",
107-
"ListenerTimeout",
108-
"NotAcceptable",
109-
"RPCError",
11076
"SecurityCheckMismatch",
11177
"SecurityError",
112-
"SeeOther",
113-
"ServiceUnavailable",
114-
"Unauthorized",
11578
"UnknownError",
11679
]
117-
__all__ += list(error_objects.keys()) # type: ignore

hydrogram/raw/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@
2828

2929

3030
__all__ = ["base", "core", "functions", "objects", "types"]
31-
__all__ += list(objects.keys()) # type: ignore

0 commit comments

Comments
 (0)