Skip to content

compile fails on 3.14 on a valid expression when -OO is set #137308

@tybug

Description

@tybug

Bug report

Bug description:

Given the following code snippet:

import ast

source = b'class A:\n    """\n    """\n'
compile(ast.parse(source), "a", "exec")

python3.13 -OO test.py passes, but python3.14 -OO test.py fails, with:

Traceback (most recent call last):
  File "/Users/tybug/Desktop/sandbox2.py", line 7, in <module>
    compile(ast.parse(source), "a", "exec")
ValueError: empty body on ClassDef

Python: 3.14.0rc1

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs 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