Skip to content
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

[3.13.0b4] f-string with precision specifier has format_spec of Constant, not JoinedStr #122300

Closed
jacobtylerwalls opened this issue Jul 26, 2024 · 7 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@jacobtylerwalls
Copy link
Contributor

jacobtylerwalls commented Jul 26, 2024

Bug report

Bug description:

Python 3.12.0 (v3.12.0:0fb18b02c8, Oct  2 2023, 09:45:56) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
>>> import ast
>>> ast.parse("f'{e:.3}'").body[0].value.values[0].format_spec
<ast.JoinedStr object at 0x1002aa050>
Python 3.13.0b4 (v3.13.0b4:567c38b4eb, Jul 18 2024, 07:28:29) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
>>> import ast
>>> ast.parse("f'{e:.3}'").body[0].value.values[0].format_spec
<ast.Constant object at 0x104af45d0>

Docs say FormattedValue.format_spec is a JoinedStr.

Reported downstream in pylint-dev/astroid#2478

Not present in 3.13.0b3

CPython versions tested on:

3.13

Operating systems tested on:

Linux, macOS

Linked PRs

@jacobtylerwalls jacobtylerwalls added the type-bug An unexpected behavior, bug, or error label Jul 26, 2024
@jacobtylerwalls jacobtylerwalls changed the title [3.13.0b4] f-string with precision specifier has format_spec of Const, not JoinedStr [3.13.0b4] f-string with precision specifier has format_spec of Constant, not JoinedStr Jul 26, 2024
@Eclips4
Copy link
Member

Eclips4 commented Jul 26, 2024

Bisected to c46d64e
cc @pablogsal

@jacobtylerwalls
Copy link
Contributor Author

Thanks for the bisect. That PR updated the docs for ast.JoinedStr to show this as the new expected result, so maybe we just need a docs update for ast.FormattedValue?

@pablogsal
Copy link
Member

Thanks for the bisect. That PR updated the docs for ast.JoinedStr to show this as the new expected result, so maybe we just need a docs update for ast.FormattedValue?

Note that the docs are not prescriptive over what the shape of the AST will be, it's just an example. The actual shape of the AST can still change due to bug fixes and grammar extensions so I would not recommend looking at those docs as a prescription with any backwards compatibility guarantees.

Being said that I can try to investigate how difficult it's to preserve this because I understand how annoying this can be downstream if you don't have anything you can match against and was like that for several versions.

@pablogsal
Copy link
Member

I think #122308 will do the trick

pablogsal added a commit to pablogsal/cpython that referenced this issue Jul 26, 2024
… elements

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
@penguinpee
Copy link

Yep. #122308 fixes the test regressions in rope and astor that I reported in #122307. Thanks!

@pablogsal
Copy link
Member

Will backport this soon

pablogsal added a commit to pablogsal/cpython that referenced this issue Jul 27, 2024
… single elements (pythonGH-122308)

(cherry picked from commit db2d8b6)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this issue Jul 27, 2024
… single elements (pythonGH-122308)

(cherry picked from commit db2d8b6)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this issue Jul 27, 2024
… single elements (pythonGH-122308)

(cherry picked from commit db2d8b6)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit that referenced this issue Jul 27, 2024
pablogsal added a commit that referenced this issue Jul 27, 2024
@pablogsal
Copy link
Member

All done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants