mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Strip None fields away
This commit is contained in:
parent
3441db17b0
commit
676f9feba8
@ -47,6 +47,15 @@ class Object:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def remove_none(obj):
|
||||||
|
if isinstance(obj, (list, tuple, set)):
|
||||||
|
return type(obj)(remove_none(x) for x in obj if x is not None)
|
||||||
|
elif isinstance(obj, dict):
|
||||||
|
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)
|
||||||
|
else:
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class Encoder(JSONEncoder):
|
class Encoder(JSONEncoder):
|
||||||
def default(self, o: Object):
|
def default(self, o: Object):
|
||||||
try:
|
try:
|
||||||
@ -57,6 +66,9 @@ class Encoder(JSONEncoder):
|
|||||||
else:
|
else:
|
||||||
return repr(o)
|
return repr(o)
|
||||||
|
|
||||||
|
if "pyrogram" in objects.get(getattr(o, "ID", "")):
|
||||||
|
return remove_none(OrderedDict([i for i in content.items()]))
|
||||||
|
else:
|
||||||
return OrderedDict(
|
return OrderedDict(
|
||||||
[("_", objects.get(getattr(o, "ID", None), None))]
|
[("_", objects.get(getattr(o, "ID", None), None))]
|
||||||
+ [i for i in content.items()]
|
+ [i for i in content.items()]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user