Skip to content

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

@sobolevn

Description

@sobolevn

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

Metadata

Metadata

Labels

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

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy