Skip to content

Commit 676f9fe

Browse files
committed
Strip None fields away
1 parent 3441db1 commit 676f9fe

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

pyrogram/api/core/object.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ def __call__(self):
4747
pass
4848

4949

50+
def remove_none(obj):
51+
if isinstance(obj, (list, tuple, set)):
52+
return type(obj)(remove_none(x) for x in obj if x is not None)
53+
elif isinstance(obj, dict):
54+
return type(obj)((remove_none(k), remove_none(v)) for k, v in obj.items() if k is not None and v is not None)
55+
else:
56+
return obj
57+
58+
5059
class Encoder(JSONEncoder):
5160
def default(self, o: Object):
5261
try:
@@ -57,7 +66,10 @@ def default(self, o: Object):
5766
else:
5867
return repr(o)
5968

60-
return OrderedDict(
61-
[("_", objects.get(getattr(o, "ID", None), None))]
62-
+ [i for i in content.items()]
63-
)
69+
if "pyrogram" in objects.get(getattr(o, "ID", "")):
70+
return remove_none(OrderedDict([i for i in content.items()]))
71+
else:
72+
return OrderedDict(
73+
[("_", objects.get(getattr(o, "ID", None), None))]
74+
+ [i for i in content.items()]
75+
)

0 commit comments

Comments
 (0)