mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Add __slots__ to PyrogramType and Update types
This commit is contained in:
parent
c611944d45
commit
ef9ed31589
@ -17,15 +17,17 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from json import dumps, JSONEncoder
|
from json import dumps
|
||||||
|
|
||||||
|
|
||||||
class PyrogramType:
|
class PyrogramType:
|
||||||
|
__slots__ = ["_client"]
|
||||||
|
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
self._client = client
|
self._client = client
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return dumps(self, cls=Encoder, indent=4)
|
return dumps(self, indent=4, default=default, ensure_ascii=False)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return getattr(self, item)
|
return getattr(self, item)
|
||||||
@ -40,15 +42,9 @@ def remove_none(obj):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class Encoder(JSONEncoder):
|
def default(o: PyrogramType):
|
||||||
def default(self, o: PyrogramType):
|
try:
|
||||||
try:
|
content = {i: getattr(o, i) for i in o.__slots__}
|
||||||
content = {
|
|
||||||
i: getattr(o, i)
|
|
||||||
for i in filter(lambda x: not x.startswith("_"), o.__dict__)
|
|
||||||
}
|
|
||||||
except AttributeError:
|
|
||||||
return repr(o)
|
|
||||||
|
|
||||||
return remove_none(
|
return remove_none(
|
||||||
OrderedDict(
|
OrderedDict(
|
||||||
@ -56,3 +52,5 @@ class Encoder(JSONEncoder):
|
|||||||
+ [i for i in content.items()]
|
+ [i for i in content.items()]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
except AttributeError:
|
||||||
|
return repr(o)
|
||||||
|
@ -26,6 +26,8 @@ class ContinuePropagation(StopIteration):
|
|||||||
|
|
||||||
|
|
||||||
class Update:
|
class Update:
|
||||||
|
__slots__ = []
|
||||||
|
|
||||||
def stop_propagation(self):
|
def stop_propagation(self):
|
||||||
raise StopPropagation
|
raise StopPropagation
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user