mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 14:35:00 +01:00
Ignore private attributes in TelegramObject.to_dict() (#1989)
This commit is contained in:
parent
a42b68933c
commit
ac7cc7fe5e
2 changed files with 10 additions and 6 deletions
|
@ -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]
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue