Skip to content

[FEATURE] TelegramObject.to_dict(recursion=value) #3146

@Bibo-Joshi

Description

@Bibo-Joshi

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

Have a dict representation of TelegramObject without having the attributes also converted to dicts

Describe the solution you'd like

Make TO.to_dict accept a parameter recursion that specifies up to which level attributes should be converted to dict. Logic:

  • recursion=None (default) recurs infinitely
  • 0 gives a dict representation but doesn't convert attributes to dicts
  • 1 converts attributes, but not attributes of attributes
  • etc

Describe alternatives you've considered

Alternatively, a simple recursion=True/False could be a step in the same direction with, having the same effect as None/0 described above

Additional context

Would e.g. allow to do ptbcontrib.send_by_kwargs(bot, chat_id=chat_id, **message.to_dict(recursion=0). See also python-telegram-bot/ptbcontrib#39 which was implemented only partly

Just a wild idea so far and of no major importance to me :)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions