-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
Clarify flag case in re
module docstring
#84197
Comments
Today I was tripped up by an inconsistency in the
The DOTALL flag appears as an uppercase S in 2 places, and as a lowercase s in one place. This is confusing, and I initially tried using the uppercase S only to get an error. I'm attaching a PR to this ticket. |
As you can see I left the old uppercase enums defined, to avoid breaking backward compatibility. We could make them trigger a DeprecationWarning. |
It is very inconvenient to use single-letter lowercase names for constants. It contradicts PEP-8: |
Well, these aren't the textbook case of a constant, since they're enums, and not defined in the global namespace. |
They are. |
Oops, my mistake. Any other idea how to solve this discrepancy? |
I do not see any issue except that you was careless when read the documentation. |
I'm gonna look past the rudeness, and I'll just say that if I was tripped up by this, after 11 years of working with Python and the re module, then people in a beginner or intermediate level could be tripped up by this as well. Here's another, simpler suggestion for preventing confusion. Replace this line in the docstring:
With this line:
There's no reason to mention the letters there because they're already mentioned. And it's helpful to add a short explanation, like the other entries in that list. |
I updated my PR to match. |
I apologize if I was rude. It's only because of my bad English. There were many translation options for my words suggested by Google Translator and I obviously picked up the wrong one. Improving documentation is always a good thing. But I leave the final decision to someone who is fluent in English. |
The root confusion is that re compilation has several variations with two sets of indicators, each with an unhelpful exception, and each combined and used in different ways.
The additional issue for docstrings is the extreme compression, including the omission (here) of 're.' prefixes. They are intended as reminders for those who have read and understood the full doc, but we try to make them as clear as possible. I am working on an alternate revision. |
re
modulere
module docstring
re
modulere
module docstring
The docstring line in question is This is exceptional in that other syntaxes in the special characters list use lower case only for syntax variables (m, n, name, id/name, yes, no). Here, each letter is a separate and literal special character. (Also exceptional is that the syntax given is illegal, as 'a', 'L', and 'u' are mutually exclusive.) The corresponding doc entry starts I suggest the following as the replacement here (followed by more 'below'). I think 'letters' pretty clearly refers to 'a', 'i', ..., and 'x' as given, and that each 'corresponds' to and sets a flag that is a separate entity. The more complicated inline flags syntax, "(?aiLmsux-imsx:...)", is omitted from the docstring. Perhaps this is intentional. The flag constants are currently introduced by My suggested more accurate and expanded replacement: |
The docstring is currently 103 lines. I intentionally replaced 1 line with 1 line that I believe to be more informative and kept the expansion of the other line to 3 lines. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: