Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
pyctrl wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
frompyctrl:fix-docs-to-match-actual-behavior

Conversation

pyctrl
Copy link

@pyctrlpyctrl commentedApr 19, 2025
edited by ZeroIntensity
Loading

Hello, let me try to help a bit with docs.

Here is an string formatting example:

In [29]: "{a-b} {-}".format(**{"-": "_-_", "a-b": "ABC"})Out[29]: 'ABC _-_'

This behaviour differs fromFormat String Syntax:

arg_name: [identifier | digit+]attribute_name: identifier

So I updatedarg_name andattribute_name syntax in that section to follow the actual behaviour:

  • replacedidentifier withattribute_name inarg_name
  • set syntax forattribute_name asanything that doesn’t contain "." or "]"

You can find original discussion threadhere


📚 Documentation preview 📚:https://cpython-previews--132736.org.readthedocs.build/en/132736/library/string.html#format-string-syntax

samuray21x reacted with thumbs up emoji
@python-cla-bot
Copy link

python-cla-botbot commentedApr 19, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@StanFromIreland
Copy link
Contributor

StanFromIreland commentedApr 19, 2025
edited
Loading

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.

@ZeroIntensityZeroIntensity added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes skip issue labelsMay 18, 2025
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 "."> +
Copy link
Member

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 bothN and as attribute names?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, any. 👌

It works the same way as kwargs in functions.

In [1]: def f(**kwargs):   ...:     print(kwargs)   ...: In [2]: d = {"-": 1, "N": 2, "ℕ": 3, "փ": 4, " ": 5}In [3]: f(**d){'-': 1, 'N': 2, 'ℕ': 3, 'փ': 4, ' ': 5}In [4]: "{-} {N} {ℕ} {փ} { }".format(**d)Out[4]: '1 2 3 4 5'

image

skirpichev reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You can even use]:

>>classC:...def__init__(self,path=()):self.path=path...def__getitem__(self,key):returnC((*self.path,key))...def__getattr__(self,name):returnC((*self.path,name))...def__str__(self):returnstr(self.path)...>>>'{].][{].\0!s}'.format_map(C())"(']', ']', '{', '\\x00')">>>'{.][{].\0!s}'.format(C())"(']', '{', '\\x00')"
Suggested change
attribute_name: <any source character except "]" or "."> +
attribute_name: <any source character except "{", "}", "[", or "."> +

Copy link
Author

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. 👌

@pyctrlpyctrlforce-pushed thefix-docs-to-match-actual-behavior branch from8ce5764 toce915deCompareMay 20, 2025 08:01
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@skirpichevskirpichevskirpichev left review comments

@ZeroIntensityZeroIntensityZeroIntensity approved these changes

@encukouencukouAwaiting requested review from encukou

Assignees
No one assigned
Labels
awaiting core reviewdocsDocumentation in the Doc dirneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesskip issueskip news
Projects
Status: Todo
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@pyctrl@StanFromIreland@encukou@skirpichev@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp