Skip to content

refactor: add enum constants #3351

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

Merged
merged 50 commits into from
Nov 22, 2022
Merged

Conversation

lemontree210
Copy link
Member

@lemontree210 lemontree210 commented Nov 8, 2022

Addresses #3107. This PR replaces #3336 that was a PR from my own fork. Instead, now it's a PR within the repository.

  • Among others, be sure to add limits for:
    • set_chat_admin_custom_title
    • set_chat_title
    • set_chat_description
    • create_new_sticker_set name, title
  • change docstrings in existing classes in constants.py:
    • add :paramref:s
  • add .. versionadded:: 20.0 to every added constant in "target" classes (e.g. like it's done for class constants in InlineQuery)

@lemontree210 lemontree210 added the ⚙️ documentation affected functionality: documentation label Nov 8, 2022
as suggested in review for PR #3336,
but in singular (rather than `...Limits`)
to conform with review for #3343
@lemontree210
Copy link
Member Author

This is not part of the code I'm changing, but I was just creating a class with limits for ReplyKeyboardMarkup and noticed this. I don't think that InlineKeyboardMarkupLimit here has actually something to do with limits for any params in Bot.send_message, contrary to what's stated in the docstring.

@lemontree210
Copy link
Member Author

I don't think that InlineKeyboardMarkupLimit here has actually something to do with limits for any params in Bot.send_message.

BTW, class InlineKeyboardMarkupLimit in constants.py doesn't seem to be used anywhere, not even in InlineKeyboardMarkup docstring.

@lemontree210

This comment was marked as resolved.

* add links to/from `InlineQueryResultLocation` and `InputLocationMessageContent`
that were not added in previous commits

* note that `Location` class does not have
limits specified for `live_period` and
`proximity_alert_radius` but `InlineQueryResultLocation`
and `InputLocationMessageContent` do
Copy link
Member Author

@lemontree210 lemontree210 left a comment

Choose a reason for hiding this comment

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

I remember that adding class constants to Bot is not optimal, but shouldn't I fully implement the approach laid out in description for #3107 in Dice? Which would mean introducing class constants for emoji and value in Dice class directly and linking them to constants.py.

+ make sure the order of constants is kept in docs
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.

you're being thorough, nice! :)

note that this approach leads to similar constants
in multiple classes
reverting changes made to telegram.dice.rst
in  cbe20e6
@lemontree210
Copy link
Member Author

Do you think I should also replace "emoji literals" in filters.py with links to constants?

@lemontree210 lemontree210 mentioned this pull request Nov 20, 2022
23 tasks
@lemontree210
Copy link
Member Author

lemontree210 commented Nov 20, 2022

Saving comments by @Bibo-Joshi here:

I vote to keep ChatIniviteLinkLimit separate from a potential ChatLimit enum, since ChatIniviteLinkLimit addresses limits of the ChatInviteLink class rather than generic chat-related limits.

Putting title limits into a ChatLimit enum is okay IMO.

I also vote to keep the current Chat* enums separate from a ChatLimit enum:

  • ChatAction is mostly related to send_chat_action and has little to do with the Chat class
  • ChatID also has little to do with the Chat class
  • ChatMemberStatus is about the ChatMember class and not about limits
  • ChatType is not about limits

@lemontree210

This comment was marked as resolved.

@Bibo-Joshi

This comment was marked as resolved.

@lemontree210

This comment was marked as outdated.

@@ -93,3 +106,45 @@ def __init__(self, value: int, emoji: str, *, api_kwargs: JSONDict = None):
"""
Copy link
Member Author

@lemontree210 lemontree210 Nov 21, 2022

Choose a reason for hiding this comment

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

This comment is about the lines above this one. I didn't add any .. versionadded to class constants that I didn't create, though I think this needs to be done. I also think that the version marking in the line immediately above this one (for BOWLING) might be wrong: a bowling emoji was added in 13.4, but the constant itself is being introduced in 20.0. So maybe all constants referring to DiceEmoji should also get the 20.0 marking.

(Since I wasn't changing those lines, I couldn't add a comment to them directly)

@lemontree210 lemontree210 marked this pull request as ready for review November 21, 2022 16:59
@lemontree210 lemontree210 self-assigned this Nov 21, 2022
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.

This PR is very high effort and simply insane. It was excruciating for me to just review over the past few days! Well done!

@harshil21 harshil21 linked an issue Nov 21, 2022 that may be closed by this pull request
@Bibo-Joshi Bibo-Joshi merged commit c3f8fcd into master Nov 22, 2022
@Bibo-Joshi Bibo-Joshi deleted the enums-instead-of-literals-3107 branch November 22, 2022 10:07
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⚙️ documentation affected functionality: documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Constant improvement
3 participants