Skip to content

Conversation

@lemontree210
Copy link
Member

closes #3770

@lemontree210 lemontree210 self-assigned this Aug 4, 2023
@lemontree210
Copy link
Member Author

  1. I put __repr__ methods right after __init__, but for Job I put it in the end because that's where __eq__ and __hash__ were.
  2. Maybe I should add angular brackets to make output look like automatic __repr__
  3. Not sure how I can access the whole schedule from Job. I can only access the time of next job execution, I think.

@harshil21
Copy link
Member

  1. I put __repr__ methods right after __init__, but for Job I put it in the end because that's where __eq__ and __hash__ were.

I actually highly prefer having magic methods in the beginning of a class, since they define the behaviour of a class. Don't know why none of the linters support such a thing. Let's make a new issue to do this if everyone thinks the same.

@Bibo-Joshi
Copy link
Member

  1. I put __repr__ methods right after __init__, but for Job I put it in the end because that's where __eq__ and __hash__ were.

I actually highly prefer having magic methods in the beginning of a class, since they define the behaviour of a class. Don't know why none of the linters support such a thing. Let's make a new issue to do this if everyone thinks the same.

I also like having all magic methods in one place. Since __init__ already is one, the start makes sense, but I'm also fine with the end usually … For this PR putting __repr__ after __init__ or where other magic methods already are sounds good 👍

  1. Maybe I should add angular brackets to make output look like automatic __repr__

I don't see really the benefit of that …

  1. Not sure how I can access the whole schedule from Job. I can only access the time of next job execution, I think.

shouldn't that be available as job.trigger?

for some reason I decided to include the size of the queue.
I think it could be helpful for the user.
Numbers of states could be useful because a user that has
multiple `ConversationHandler`s might easily recognize the
handler by these numbers even if it has no name.
@lemontree210
Copy link
Member Author

I should create some tests for these methods, right?

Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should create some tests for these methods, right?

Yes please! :) Even if we don't document this behavior I'd like to avoid regressions.

I only just now looked at the changes for the first time and I see that your style of __repr__ indeed reads like a short description. It definetily has benefits in terms of being easier to understand 👍 The downside is that it's easier to get a bit lengthy so that I would suggest to double check the wording & printed information in terms of length. I also now better understand your question about <…> :D That does in fact make more sense to me now as with this style it is more important to have some markers for the start and end of the representation. You could write a small helper for f"<{stuff}>" to make it easy to apply the same style everywhere.

TBH I always had something like Application(bot=…) in mind, but I do see that this assumption is in no way the only (or even "best") thing to do. The upside is that it's shorter, the downside is that's a bit less easy to understand. A downside is that it suggests that you can instantiate the object like that which is not always the case. Using e.g. square brackets instead could alleviate the problem a bit, but I admit that I like the general descriptive style a bit better for these "highlevel" classes (note that for the TG classes which are mostly "data classes", the ClassName(…) repr still makes sense for me).

@lemontree210
Copy link
Member Author

note that for the TG classes which are mostly "data classes", the ClassName(…) repr still makes sense for me)

I don' think we ever planned to create __repr__ for Telegram classes though (i.e. subclasses of TelegramObject) 🤔 But maybe I should try this style for the other classes as well and see how it goes.

@Bibo-Joshi
Copy link
Member

note that for the TG classes which are mostly "data classes", the ClassName(…) repr still makes sense for me)

I don' think we ever planned to create __repr__ for Telegram classes though (i.e. subclasses of TelegramObject) 🤔 But maybe I should try this style for the other classes as well and see how it goes.

Sure we did:

@lemontree210
Copy link
Member Author

Sure we did

OK, I was being inattentive and imprecise (need a third flaw to make a combo). But the point of my message was, "we're not doing anything to TO here in this PR" :) In your comment you were obviously referring to the existing practice, and I misunderstood it.

@lemontree210
Copy link
Member Author

A downside is that it suggests that you can instantiate the object like that which is not always the case.

How about we write something like Application(param1=value1, param2=value2, ... ) - with an ellipsis to make it clear that these params are not enough to instantiate the application?

@Bibo-Joshi
Copy link
Member

A downside is that it suggests that you can instantiate the object like that which is not always the case.

How about we write something like Application(param1=value1, param2=value2, ... ) - with an ellipsis to make it clear that these params are not enough to instantiate the application?

I'm not sure if that's much better. Thinking about it, e.g. for Jobs the trigger is actually not an argument that we directly pass to neither Job nor run_*, so showing it as kind of argument would be rather confusing, I guess 🤔

Copy link
Member

@harshil21 harshil21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good feature to have!

Copy link
Member

@Poolitzer Poolitzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it

@Bibo-Joshi
Copy link
Member

I was about to hit merge - but then I remembered one more thing 🙈 For TelegramObject we documented all the dunder methods and for consistency I would vote to do the same here. However, the code change itself is already approved and I don't want to stretch this PR needlessly. We can do this as a follow-up PR. @lemontree210 please let me now what you prefer

@lemontree210
Copy link
Member Author

For TelegramObject we documented all the dunder methods and for consistency I would vote to do the same here.

consistency is key! :)

Copy link
Member

@harshil21 harshil21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm again :)

Copy link
Member

@Poolitzer Poolitzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@harshil21 harshil21 added enhancement 📋 pending-merge work status: pending-merge labels Sep 15, 2023
@Bibo-Joshi
Copy link
Member

Bibo-Joshi commented Sep 15, 2023

DS failure unrelated - see #3888. Merging.

PS: Will open a follow-up issue on #3826 (comment)

PPS: I'm blind - that was already addressed

@Bibo-Joshi Bibo-Joshi merged commit 9c7298c into master Sep 15, 2023
@Bibo-Joshi Bibo-Joshi deleted the repr-for-classes-3770 branch September 15, 2023 19:35
@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 2023
@Bibo-Joshi Bibo-Joshi added 🔌 enhancement pr description: enhancement and removed enhancement labels Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🔌 enhancement pr description: enhancement 📋 pending-merge work status: pending-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Provide a "official" string representation for most classes

5 participants