Skip to content

[BUG] Subscription: Doesn't work for 'from' & Other Improvements #2709

@Bibo-Joshi

Description

@Bibo-Joshi

Steps to Reproduce

  1. get an instance of Message
  2. run message['from'], message['from_user'] and message['false_key']
  3. the first gives None, the second gives the user, the 3rd gives None

Expected behaviour

  1. both message['from'] and message['from_user'] return the user
  2. message['false_key'] raises KeyError. This behavior was apparently lost in Add __slots__ #2345 for some reason

Actual behaviour

  1. message['from'] gives None
  2. message['from_user'] return the user
  3. message['false_key'] returns None

Operating System

Any

Version of Python, python-telegram-bot & dependencies

branches master and v14

Relevant log output

No response

Additional Context

  • This is easy to fix by adapting TelegramObject.__getitem__ to raise KeyError when the attribute is not found and introducing a special case where obj['from'] looks up 'from_user'.

  • In addition, Message overrides __getitem__, but this is actually not necessary. This should be removed.

  • A PR for this should be based on v14. see Hacktoberfest 2021 #2681

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions