🐛 TLObject: Fix read return None instead of raise KeyError

This commit is contained in:
Sam 2022-01-19 22:21:30 +08:00
parent a634541c9b
commit 71ebe8bcac
Signed by: sam01101
GPG Key ID: 42D7B6D13FF5E611

View File

@ -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