Skip to content

Setting custom attributes on objects of the PTB library is deprecated? #2555

Discussion options

You must be logged in to vote

Hi. Thanks for reaching out.

We added __slots__ mostly for the benefits they can bring in terms of menory usage and performance. Disallowing users from adding custom attributes to PTB-classes in the future is more a side effect of this, but one that I support.

Dynamically adding attributes to classes is certainly a useful feature for some use cases in Python, one example being Handler.collect_additional_context in PTB, which encourages you to add custom attributes to a CallbackContext object (and this will ofc work in future versions).
However, there are also many cases were I'd argue that there is a cleaner solution. E.g. for the types defined by the Bot API, I'd argue that it's unnatura…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@copy-plus-pasta-equals-love
Comment options

Comment options

You must be logged in to vote
1 reply
@copy-plus-pasta-equals-love
Comment options

Answer selected by copy-plus-pasta-equals-love
Comment options

You must be logged in to vote
1 reply
@copy-plus-pasta-equals-love
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants