-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Update "Format String Syntax" documentation block to match actual behaviour #132736
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
base: main
Are you sure you want to change the base?
Conversation
|
See: #127833 We could update the whole snippet now. I'd ask Petr for what his plan was but he's unavailable at the moment. |
Doc/library/string.rst
Outdated
| arg_name: [`~python-grammar:identifier` | `~python-grammar:digit`+] | ||
| attribute_name: `~python-grammar:identifier` | ||
| arg_name: [`~python-grammar:digit`+ | `attribute_name`] | ||
| attribute_name: <any source character except "]" or "."> + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any?
Are you sure that can use both N and ℕ as attribute names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can even use ]:
>> class C:
... def __init__(self, path=()): self.path = path
... def __getitem__(self, key): return C((*self.path, key))
... def __getattr__(self, name): return C((*self.path, name))
... def __str__(self): return str(self.path)
...
>>> '{].][{].\0!s}'.format_map(C())
"(']', ']', '{', '\\x00')"
>>> '{.][{].\0!s}'.format(C())
"(']', '{', '\\x00')"| attribute_name: <any source character except "]" or "."> + | |
| attribute_name: <any source character except "{", "}", "[", or "."> + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, thank you! 👍
Updated the PR. 👌
8ce5764 to
ce915de
Compare
|
Can I help here more with something? |

Hello, let me try to help a bit with docs.
Here is an string formatting example:
This behaviour differs from Format String Syntax:
So I updated
arg_nameandattribute_namesyntax in that section to follow the actual behaviour:identifierwithattribute_nameinarg_nameattribute_nameasanything that doesn’t contain "." or "]"You can find original discussion thread here
📚 Documentation preview 📚: https://cpython-previews--132736.org.readthedocs.build/en/132736/library/string.html#format-string-syntax