🐛 TLObject: Fix read return None instead of raise KeyError

This commit is contained in:
Sam 2022-01-19 22:21:30 +08:00
parent 6c078c38d0
commit 2a7b83d668
Signed by: sam01101
GPG Key ID: 42D7B6D13FF5E611

View File

@ -18,7 +18,7 @@
from io import BytesIO from io import BytesIO
from json import dumps 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 from ..all import objects
@ -29,8 +29,11 @@ class TLObject:
QUALNAME = "Base" QUALNAME = "Base"
@classmethod @classmethod
def read(cls, b: BytesIO, *args: Any) -> Any: def read(cls, b: BytesIO, *args: Any) -> Optional["TLObject"]:
return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args) 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: def write(self, *args: Any) -> bytes:
pass pass