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
Constant improvement #3107
Comments
Hey, I'm new to open source and want to learn how to contribute, and I can't quite get what needs to be done here. Can you guide me on which doc is required in order to be updated or changed? |
Hey, nice to hear. So I already linked to a few examples in my original message. Have a look at the source doc string of send_poll. As you can see in If you have a look at that linking, you can see that it references MAX_QUESTION_LENGTH in the Poll file. In the source of Poll, you can see that you have been bamboozled and the actual source for these variables lies in the constants.py file, MAX_QUESTION_LENGTH is just a link to In the source of constants, you can finally see how it is implemented: An IntEnum Class which has the values mapped to their respective key. The issue is that we only did this sparingly thus far, whenever we thought of it. I would like to replace every limit currently written out in the docstrings with links to constants files. We as maintainer still have decide on a couple things. Now there is the question of what you can do in the meantime. What would be an amazing help if you can go through the whole documentation (maybe scroll through telegrams one, its easier to read one after another since its just one page). Any missed limitation (last point in the list below) would be hugely appreciated pointed out, since that would require a decision from us before one can implement it. Otherwise you could go ahead and convert some obvious limitations already. On a side-note, I will push an example improvements of the |
Maintainers have to decide on:
|
I would say yes for the Min only if it's non zero, e.g. in sendPoll.open_period and switch_pm_parameter that would make sense. But not in for e.g. answer_callback_query.text
I don't really understand this. Do you want to enforce this at runtime? I thought we decided against that in #2901?
Also no, see above linked issue + I think they can change over time so that's just added maintenance for us. |
No nothing here is enforcing at runtime, its a question of how we interpret entries to our constant files. On one side we have the usual API constants, on the others we have the max/min limits of specific calls/objects, so people can do The last two entries in the list are continuations of the second type. With the second they could do
They have never. But thats the same for any other entry to constants. |
Ah okay. I guess having those validation functions for "constants" is not very fitting, since it's meant to be hardcoded values and nothing else? Maybe having them in a separate |
Or just regex-search for integers 🙂
+1
I agree with harshil here. constants is for constants, not validators. Personally I see the main advantage of the constants module in not having to hard code values/define those constants on your own. How a user uses them is another question.
Punshline the same as above, with the addition that a maintained list of ISO-language codes very likely already exists somewhere and I don't see a need to duplicate that in PTB. |
Alright, lets drop validation stuff for now and let these limits in the doc strings, we can stick to the other hardcoded values. One example on how this is implemented is visual in #3112: The doc strings of InputInvoiceMessageContent and bot.send_invoice changed, the constants were linked in Invoice and finally implemented in InvoiceLimits enum in the constants file. Hope this makes clear how we expect this issue to be implemented. |
I kind of like getting rid of magical numbers so I could dive into this unless you'd like me to focus on something more pressing |
How about default values? My guess is that we do not put them into the enumerations because default values (if we are talking about Telegram API, not additional kwargs) are not passed to Telegram: That would mean that, for example, for parameter Even if I added a constant for that too, that wouldn't mean a change in the signature of The example for |
@lemontree210 yes, that understanding is correct. No need to make constants for default values. |
The files actually demonstrate two approaches: class Invoice contains class constants that are linked to InvoiceLimits enum, but class Bot shows a different approach to Which approach should I follow? I assume the former (like in |
I don't think we should add class constants for |
We currently have quite some limits still hard coded into the docstrings, for example vcard, telegram.Bot.send_poll#explanation or #open_period. We also could think about including switch_pm_parameter somehow. I would like to collect the thoughts of the maintainers here and maybe motivate someone from the community to contribute this since it is quite an "easy" addition to the project.
The text was updated successfully, but these errors were encountered: