New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Provide a "official" string representation for most classes #3770
Comments
Hello @harshil21 , I'd like to take care of this. |
@CarlosZBent hi, at the moment the team would like to discuss this proposal. If we're going ahead with it, we'll notify you. |
Sounds good, thanks for letting me know |
A few initial toughts:
As a general thought: |
My impression is that in terms of the common understanding of the |
I also feel the same as @lemontree210. Also just remembered that adding a
For complex setups, it can be useful to print the builder and see what has been already added. |
I disagree with that. Providing an (almost) unambiguous representation doesn't necessarily coincide with being able to recreate the object. E.g. if an object has a unique ID, printing that ID suffices for unambiguous representation (end hence pythons default implementation uses
How so?
Would you mind elaborating this use case? Bots are rarely run in an interactive shell, so I would expect that if you wanted to inspect the builder, you'd rather have to do that automatically at runtime and for that parsing string representations seems like an insane approach … |
For users new to a particular function / the library itself, it can be useful to see what the object is, like what attributes it has.
Ok, I don't mind showing only certain attributes in the representation, anything is better than the default, which is nothing useful imo.
you mean implementing I agree with your list of which classes should get a repr btw (except appbuilder ^)
✅ |
The "How so?" was about why string representations are especially useful for jupyter/Ipython :)
I mean that parsing a string representation of
Sorry, I still don't see how a custom string representation of
❤️ |
I like the following quote from an SO discussion:
Take e.g. I would also rather agree with the same SO reply saying that virtually any class has to have a I would still argue that in some cases you're rather talking about |
IMO the difference between
Let's maybe clarify what our views on "needs to know" are :) From my above argumentation, what a developer needs to know about an object (in the logs/debug output) is the info that they need to identify the object (uniquely, at best) and to know which places in the code to look for when trying to fix exceptions. For the |
I know what you mean, it's somewhat strange that in our case the line between "users" and "developers" is sort of blurred :)
This one really got my attention because we're thinking of not adding Maybe the intermediate approach would be to find classes that we want to show different info about for PTB developers ("developers") as opposed to bot developers that use PTB ("users"). These classes might show a lot of debug information in |
|
I agree with Hinrich on only overriding |
@CarlosZBent I guess the discussions have been resolved now. Are you sitll interested in PRing for this? |
@Bibo-Joshi I'm sorry but no, I'm unable at this moment. |
1 similar comment
@Bibo-Joshi I'm sorry but no, I'm unable at this moment. |
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
We should define a
__repr__
for most telegram classes, since it is useful for debugging/inspection purposes.Describe the solution you'd like
Define a
__repr__
in all base classes. Typically, the representation should be of the form<...some useful description...>
. We can just have it so that it returns the expression which can be used to recreate the object.Describe alternatives you've considered
No response
Additional context
First suggested in #3759 (comment)
The text was updated successfully, but these errors were encountered: