diff --git a/telegram/base.py b/telegram/base.py index 3431396c9..65c43678e 100644 --- a/telegram/base.py +++ b/telegram/base.py @@ -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] diff --git a/tests/test_telegramobject.py b/tests/test_telegramobject.py index 66f52dbfb..156c43b65 100644 --- a/tests/test_telegramobject.py +++ b/tests/test_telegramobject.py @@ -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}