diff --git a/pyrogram/raw/core/tl_object.py b/pyrogram/raw/core/tl_object.py index b094f7d0..cd16aa0f 100644 --- a/pyrogram/raw/core/tl_object.py +++ b/pyrogram/raw/core/tl_object.py @@ -18,7 +18,7 @@ from io import BytesIO from json import dumps -from typing import cast, List, Any, Union, Dict +from typing import cast, List, Any, Union, Dict, Optional from ..all import objects @@ -29,8 +29,11 @@ class TLObject: QUALNAME = "Base" @classmethod - def read(cls, b: BytesIO, *args: Any) -> Any: - return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args) + def read(cls, b: BytesIO, *args: Any) -> Optional["TLObject"]: + function_name = objects.get(int.from_bytes(b.read(4), "little")) + if not function_name: + return None + return cast(TLObject, function_name).read(b, *args) def write(self, *args: Any) -> bytes: pass