-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Fix and update string/byte literals in help() #77603
Comments
Right now, for string/byte literals help() shows, for example: No Python documentation found for 'r'. PR fixes the quotation mark removal and updates the list with f and u literals, while also adding uppercase versions of all literals. While the list is install incomplete (e.g., fR and the others could be listed) I believe that's too much. |
*While the list is still incomplete |
Interesting, I didn't know that pydoc supports this. Specifying all possible prefixes is cumbersome and errorprone. The number of combinations grows exponentially with adding new letters. I suggest either to specify only lower-case variants and generate all variants with upper-case letters (as it done in the tokenize module) or always calls the lower() method when look up in the symbols dictionary. It may be worth to add a special topic for f-strings. |
It's not clear to me what you're typing to get the output in the first message. Can you clarify? Is this at the interactive prompt? |
Eric, I entered "r'" in the interactive prompt. Serhiy, using the code in tokenize, I got a total of 144 combinations. For comparison, the list of symbols help() shows, after the proposed change, has 67 items. IMHO, we should compromise. Maybe just mentioning the letters? With no quoting character. I do know that this can be confusing, since J is shown as a letter but it's used as a suffix unlike b/f/r/u... What do you think? |
To get the 144 combinations I used the logic in tokenize.py: import re
def _combinations(*l):
return set(
x + y for x in l for y in l + ("",) if x.casefold() != y.casefold()
)
_strprefixes = (
_combinations('r', 'R', 'f', 'F') | _combinations('r', 'R', 'b', 'B') | {'u', 'U', 'ur', 'uR', 'Ur', 'UR'}
)
triple_quoted = (
{"'''", '"""'} | {f"{prefix}'''" for prefix in _strprefixes} | {f'{prefix}"""' for prefix in _strprefixes}
)
single_quoted = (
{"'", '"'} | {f"{prefix}'" for prefix in _strprefixes} | {f'{prefix}"' for prefix in _strprefixes}
)
all_combinations = _strprefixes | single_quoted | triple_quoted
print(' '.join(list(all_combinations)))
print(len(all_combinations)) |
I don't think we need to support prefixes without quotes or with triple qoutes. 'ur' is not valid prefix. Using simplified code from tokenize: _strprefixes = [''.join(u) + q
for t in ('b', 'r', 'u', 'f', 'br', 'rb', 'fr', 'rf')
for u in itertools.product(*[(c, c.upper()) for c in t])
for q in ("'", '"')] Or you can use tokenize._all_string_prefixes() directly: _strprefixes = [p + q
for p in tokenize._all_string_prefixes()
for q in ("'", '"')] But it may be simple to just convert the string to lower case before looking up in the symbols dict. Then _strprefixes = [p + q
for p in ('b', 'r', 'u', 'f', 'br', 'rb', 'fr', 'rf')
for q in ("'", '"')] |
And what should symbols show in pydoc? Should symbols show:
Depending on that, we can choose one of the options you mentioned. |
Option 2 LGTM. |
I have updated the PR. Now symbols show: Here is a list of the punctuation symbols which Python assigns special meaning != + <= __
** < ^ |= I don't understand how topics.py gets autogenerated by Sphinx (by te way, it says it was generated on January 2018), so I'm having trouble with using a more specific topic for f'. |
Thank you for your contribution Andrés! I just wondering how did you discover this bug? |
I was exploring pydoc, saw the literals as available help "terms" on the sysmbols section, and tried reading the help for one of them. I learnt about IDLE debugging to trace this bug :) |
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: