Skip to content

ast.parse(..., mode='single') parses of multiple statements which are then not unparsed #129598

@tom-pytel

Description

@tom-pytel

Bug report

Bug description:

$ ./python
Python 3.14.0a4+ (heads/test:d906bde250, Feb  2 2025, 11:08:38) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> a = ast.parse('i = 1; j = 2', mode='single')
>>> print(ast.dump(a, indent=2))
Interactive(
  body=[
    Assign(
      targets=[
        Name(id='i', ctx=Store())],
      value=Constant(value=1)),
    Assign(
      targets=[
        Name(id='j', ctx=Store())],
      value=Constant(value=2))])
>>> ast.unparse(a)
'j = 2'

My guess the ast.parse() should probably error?

CPython versions tested on:

3.14, 3.12, 3.13, 3.11, 3.10

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytopic-parsertype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions