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 4 commits into
Conversation
|
The following commit authors need to sign the Contributor License Agreement: |
|
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.
There was a problem hiding this comment.
Please check my wording and solution with digital_number.
ce915de to
1015809
Compare
Documentation build overview
32 files changed ·
|
robsdedude
left a comment
There was a problem hiding this comment.
As a side-note: I (and a fair few others I've interacted with on GH) don't like force pushes on PRs once a review has started. It makes it harder for reviewers to follow what has changed. For a ±4 lines PR this isn't such a big deal, but still.
Other than that and the nit pick, I'd say this is looking good 👌
Co-authored-by: Robsdedude <dev@rouvenbauer.de>

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