From 2a7b83d66885d8089627b14674739d8960948674 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 19 Jan 2022 22:21:30 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20TLObject:=20Fix=20read=20return?= =?UTF-8?q?=20None=20instead=20of=20raise=20KeyError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyrogram/raw/core/tl_object.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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