Skip to content

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

Closed

Description

@jacobtylerwalls

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

Activity

  1. 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`[/+] on Jul 26, 2024
  2. Eclips4 commented on Jul 26, 2024

    @Eclips4
    Member

    Bisected to c46d64e
    cc @pablogsal

  3. jacobtylerwalls commented on Jul 26, 2024

    @jacobtylerwalls
    ContributorAuthor

    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?

  4. pablogsal commented on Jul 26, 2024

    @pablogsal
    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.

  5. added a commit that references this issue on Jul 26, 2024
  6. pablogsal commented on Jul 26, 2024

    @pablogsal
    Member

    I think #122308 will do the trick

  7. added 2 commits that reference this issue on Jul 26, 2024
  8. penguinpee commented on Jul 26, 2024

    @penguinpee

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

  9. pablogsal commented on Jul 26, 2024

    @pablogsal
    Member

    Will backport this soon

  10. added 5 commits that reference this issue on Jul 27, 2024
  11. pablogsal commented on Jul 27, 2024

    @pablogsal
    Member

    All done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions