mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-02-16 18:31:45 +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()
|
data = dict()
|
||||||
|
|
||||||
for key in iter(self.__dict__):
|
for key in iter(self.__dict__):
|
||||||
if key in ('bot',
|
if key == 'bot' or key.startswith('_'):
|
||||||
'_id_attrs',
|
|
||||||
'_credentials',
|
|
||||||
'_decrypted_credentials',
|
|
||||||
'_decrypted_data',
|
|
||||||
'_decrypted_secret'):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
value = self.__dict__[key]
|
value = self.__dict__[key]
|
||||||
|
|
|
@ -74,3 +74,12 @@ class TestTelegramObject(object):
|
||||||
|
|
||||||
monkeypatch.setattr('telegram.TelegramObject.to_dict', lambda _: d)
|
monkeypatch.setattr('telegram.TelegramObject.to_dict', lambda _: d)
|
||||||
telegram_object.to_json()
|
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…
Add table
Reference in a new issue