Ignore private attributes in TelegramObject.to_dict() (#1989)

This commit is contained in:
n5y 2020-06-10 23:21:25 +03:00 committed by GitHub
parent a42b68933c
commit ac7cc7fe5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -57,12 +57,7 @@ class TelegramObject(object):
data = dict()
for key in iter(self.__dict__):
if key in ('bot',
'_id_attrs',
'_credentials',
'_decrypted_credentials',
'_decrypted_data',
'_decrypted_secret'):
if key == 'bot' or key.startswith('_'):
continue
value = self.__dict__[key]

View file

@ -74,3 +74,12 @@ class TestTelegramObject(object):
monkeypatch.setattr('telegram.TelegramObject.to_dict', lambda _: d)
telegram_object.to_json()
def test_to_dict_private_attribute(self):
class TelegramObjectSubclass(TelegramObject):
def __init__(self):
self.a = 1
self._b = 2
subclass_instance = TelegramObjectSubclass()
assert subclass_instance.to_dict() == {'a': 1}