GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `f'"{var:}"'` adds redundant empty string literal in AST in 3.12 · Issue #106396 · python/cpython

f'"{var:}"' adds redundant empty string literal in AST in 3.12 #106396

New issue
Copy link
New issue
Copy link
Closed
Closed
f'"{var:}"' adds redundant empty string literal in AST in 3.12#106396
Copy link
Assignees
pablogsallysnikolaou
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@sobolevn
sobolevn
opened on Jul 4, 2023
Issue body actions

3.11:

>>> import ast
>>> print(ast.dump(ast.parse("""f'"{var:}"'"""), indent=2))
Module(
  body=[
    Expr(
      value=JoinedStr(
        values=[
          Constant(value='"'),
          FormattedValue(
            value=Name(id='var', ctx=Load()),
            conversion=-1,
            format_spec=JoinedStr(values=[])),
          Constant(value='"')]))],
  type_ignores=[])

3.12:

>>> import ast
>>> print(ast.dump(ast.parse("""f'"{var:}"'"""), indent=2))
Module(
  body=[
    Expr(
      value=JoinedStr(
        values=[
          Constant(value='"'),
          FormattedValue(
            value=Name(id='var', ctx=Load()),
            conversion=-1,
            format_spec=JoinedStr(
              values=[
                Constant(value='')])),
          Constant(value='"')]))],
  type_ignores=[])

This affects several linters:

  1. Fix parse test case on Python 3.12 mypy#15577
  2. B907 crashes when bugbear is run on Python 3.12 PyCQA/flake8-bugbear#393

Is this a bug? Or is it a feature?

Linked PRs

  • gh-106396: Special-case empty format spec to gen empty JoinedStr node #106401
  • [3.12] gh-106396: Special-case empty format spec to gen empty JoinedStr node (GH-106401) #106416
Reacted by sunmy2019

Activity

  1. sobolevn
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.12only security fixesonly security fixes
    on Jul 4, 2023
  2. AlexWaygood
    assigned
    pablogsal
    and
    lysnikolaou
    on Jul 4, 2023
  3. AlexWaygood
    added
    3.13only security fixesonly security fixes
    on Jul 4, 2023
  4. sunmy2019 commented on Jul 4, 2023

    @sunmy2019
    sunmy2019
    on Jul 4, 2023
    Member
    More actions

    First of all, it is not wrong. We do have an empty format spec string here.

    Fixing it for compatibility reasons is also acceptable to me. I am 60-40 towards fixing it.

  5. lysnikolaou commented on Jul 4, 2023

    @lysnikolaou
    lysnikolaou
    on Jul 4, 2023
    Member
    More actions

    I'd say let's fix it both for compatibility and for consistency with things like an empty f-string, which is also a JoinedStr with an empty values array.

    cpython on main via C v14.0.3-clang via 🐍 pyenv 3.11.3 
    ❯ ./python.exe           
    Python 3.13.0a0 (heads/main:6c60684bf5, Jul  4 2023, 11:09:56) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ast
    >>> print(ast.dump(ast.parse("""f''"""), indent=2))
    Module(
      body=[
        Expr(
          value=JoinedStr(values=[]))],
      type_ignores=[])
    >>> print(ast.dump(ast.parse("""f'"{var:}"'"""), indent=2))
    Module(
      body=[
        Expr(
          value=JoinedStr(
            values=[
              Constant(value='"'),
              FormattedValue(
                value=Name(id='var', ctx=Load()),
                conversion=-1,
                format_spec=JoinedStr(
                  values=[
                    Constant(value='')])),
              Constant(value='"')]))],
      type_ignores=[])
    Reacted by Alex Waygood
  6. lysnikolaou
    added 2 commits that reference this issue on Jul 4, 2023

    pythongh-106396: Special-case empty format spec to gen empty JoinedSt…

    a6152ae

    gh-106396: Special-case empty format spec to gen empty JoinedStr node (…

    dfe4de2
  7. miss-islington
    added a commit that references this issue on Jul 4, 2023

    pythongh-106396: Special-case empty format spec to gen empty JoinedSt…

    741e919
  8. lysnikolaou
    closed this as completedon Jul 4, 2023
  9. lysnikolaou
    added a commit that references this issue on Jul 4, 2023

    [3.12] gh-106396: Special-case empty format spec to gen empty JoinedS…

    930df7b
  10. carljm
    added a commit that references this issue on Jul 5, 2023

    Merge branch 'main' into modulelocals

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

Metadata

Metadata

Assignees

  • @lysnikolaou
    lysnikolaou
  • @pablogsal
    pablogsal

Labels

3.12only security fixesonly security fixes3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.