gh-150626: Update "Format String Syntax" documentation block to match actual behaviour#132736
gh-150626: Update "Format String Syntax" documentation block to match actual behaviour#132736pyctrl wants to merge 1 commit into
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. |
| 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.
Any?
Are you sure that can use both N and ℕ as attribute names?
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
You are right, thank you! 👍
Updated the PR. 👌
8ce5764 to
ce915de
Compare
|
Can I help here more with something? |
|
This PR is stale because it has been open for 30 days with no activity. |
| 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.
| attribute_name: <any source character except "{", "}", "[", or "."> + | |
| attribute_name: <any source character except "{", "}", "[", ".", "!", or ":"> + |
"!", ":", and "!" are also invalid attribute names.
| field_name: `arg_name` ("." `attribute_name` | "[" `element_index` "]")* | ||
| arg_name: [`~python-grammar:identifier` | `~python-grammar:digit`+] | ||
| attribute_name: `~python-grammar:identifier` | ||
| arg_name: [`~python-grammar:digit`+ | `attribute_name`] |
There was a problem hiding this comment.
TL;DR: any str.isdecimal string works for indexing, not just roman decimal digits ("0"..."9") . "١" for example is also valid.

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