🐛 TLObject: Fix read return None instead of raise KeyError
This commit is contained in:
parent
6c078c38d0
commit
2a7b83d668
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user