Skip to content

IndentationError on last token produces wrong error message when using PyCF_ALLOW_INCOMPLETE_INPUT #108085

@lysnikolaou

Description

@lysnikolaou

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

3.11, 3.12, CPython main branch

Operating systems tested on:

macOS

Output from running 'python -VV' on the command line:

Python 3.13.0a0 (heads/main:e35c722d22, Aug 17 2023, 15:02:07) [Clang 14.0.3 (clang-1403.0.22.14.1)]

A clear and concise description of the bug:

I'm currently trying to test the code and codeop modules more intensively, in order to figure out whether we could use them as the default REPL. When compiling a piece of source code in single mode and with PyCF_ALLOW_INCOMPLETE_INPUT enabled, the SyntaxError produced is wrong:

❯ ./python.exe    
Python 3.13.0a0 (heads/main:e35c722d22, Aug 17 2023, 15:02:07) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = """\
... for _ in range(10):
... hello"""
>>> PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
>>> compile(a, '<stdin>', 'single', PyCF_ALLOW_INCOMPLETE_INPUT)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2
    hello
    ^^^^^
SyntaxError: incomplete input

This was probably introduced by 69e1097. I know it's an issues that's hard to solve and I'm not sure whether it's going to be worth the effort, but let's have that discussion.

cc @pablogsal

Metadata

Metadata

Assignees

Labels

interpreter-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