Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty unclosed f-string does not directly raise a SyntaxError in the REPL #103727

Closed
lysnikolaou opened this issue Apr 23, 2023 · 3 comments
Closed
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@lysnikolaou
Copy link
Contributor

lysnikolaou commented Apr 23, 2023

Bug report

This is another bug introduced in 1ef61cf. When typing an empty single-quoted unclosed f-string in the REPL, another line is added and input is expected, before a SyntaxError is raised.

Before 1ef61cf:

❯ ./python.exe 
Python 3.12.0a7+ (tags/v3.12.0a7-153-ga6b07b5a34:a6b07b5a34, Apr 23 2023, 13:18:40) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f'
  File "<stdin>", line 1
    f'
    ^
SyntaxError: unterminated string literal (detected at line 1)

Current main:

❯ ./python.exe 
Python 3.12.0a7+ (heads/main:05b3ce7339, Apr 23 2023, 13:26:24) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f"
... 
  File "<stdin>", line 1
    f"
    ^
SyntaxError: unterminated f-string literal (detected at line 2)
>>> f"
... asdnc
  File "<stdin>", line 1
    f"
    ^
SyntaxError: unterminated f-string literal (detected at line 2)
>>> f"
... asdasd"
  File "<stdin>", line 1
    f"
    ^
SyntaxError: unterminated f-string literal (detected at line 2)

Linked PRs

@lysnikolaou lysnikolaou added the type-bug An unexpected behavior, bug, or error label Apr 23, 2023
@lysnikolaou lysnikolaou self-assigned this Apr 23, 2023
@terryjreedy
Copy link
Member

In IDLE, which uses code.interactive_interpreter, which ultimately uses codeop._maybe_compile, I get 'SyntaxError: incomplete input' in installed 3.12.0a7 and the new message at line 1 in fresh repository 3.12.0a7+.

@lysnikolaou
Copy link
Contributor Author

lysnikolaou commented Apr 23, 2023

codeop._maybe_compile uses compile, which doesn't encounter the problem mentioned here.

It's got to do with the interactive mode, where we advance the tokenizer far enough (to backup again afterwards) that a newline character alone is not enough for the syntax error to be emitted directly.

lysnikolaou added a commit to lysnikolaou/cpython that referenced this issue Apr 24, 2023
carljm added a commit to carljm/cpython that referenced this issue Apr 24, 2023
* main: (53 commits)
  pythongh-102498 Clean up unused variables and imports in the email module  (python#102482)
  pythongh-99184: Bypass instance attribute access in `repr` of `weakref.ref` (python#99244)
  pythongh-99032: datetime docs: Encoding is no longer relevant (python#93365)
  pythongh-94300: Update datetime.strptime documentation (python#95318)
  pythongh-103776: Remove explicit uses of $(SHELL) from Makefile (pythonGH-103778)
  pythongh-87092: fix a few cases of incorrect error handling in compiler (python#103456)
  pythonGH-103727: Avoid advancing tokenizer too far in f-string mode (pythonGH-103775)
  Revert "Add tests for empty range equality (python#103751)" (python#103770)
  pythongh-94518: Port 23-argument `_posixsubprocess.fork_exec` to Argument Clinic (python#94519)
  pythonGH-65022: Fix description of copyreg.pickle function (python#102656)
  pythongh-103323: Get the "Current" Thread State from a Thread-Local Variable (pythongh-103324)
  pythongh-91687: modernize dataclass example typing (python#103773)
  pythongh-103746: Test `types.UnionType` and `Literal` types together (python#103747)
  pythongh-103765: Fix 'Warning: py:class reference target not found: ModuleSpec' (pythonGH-103769)
  pythongh-87452: Improve the Popen.returncode docs
  Removed unnecessary escaping of asterisks (python#103714)
  pythonGH-102973: Slim down Fedora packages in the dev container (python#103283)
  pythongh-103091: Add PyUnstable_Type_AssignVersionTag (python#103095)
  Add tests for empty range equality (python#103751)
  pythongh-103712: Increase the length of the type name in AttributeError messages (python#103713)
  ...
carljm added a commit to carljm/cpython that referenced this issue Apr 24, 2023
* superopt: (82 commits)
  pythongh-101517: fix line number propagation in code generated for except* (python#103550)
  pythongh-103780: Use patch instead of mock in asyncio unix events test (python#103782)
  pythongh-102498 Clean up unused variables and imports in the email module  (python#102482)
  pythongh-99184: Bypass instance attribute access in `repr` of `weakref.ref` (python#99244)
  pythongh-99032: datetime docs: Encoding is no longer relevant (python#93365)
  pythongh-94300: Update datetime.strptime documentation (python#95318)
  pythongh-103776: Remove explicit uses of $(SHELL) from Makefile (pythonGH-103778)
  pythongh-87092: fix a few cases of incorrect error handling in compiler (python#103456)
  pythonGH-103727: Avoid advancing tokenizer too far in f-string mode (pythonGH-103775)
  Revert "Add tests for empty range equality (python#103751)" (python#103770)
  pythongh-94518: Port 23-argument `_posixsubprocess.fork_exec` to Argument Clinic (python#94519)
  pythonGH-65022: Fix description of copyreg.pickle function (python#102656)
  pythongh-103323: Get the "Current" Thread State from a Thread-Local Variable (pythongh-103324)
  pythongh-91687: modernize dataclass example typing (python#103773)
  pythongh-103746: Test `types.UnionType` and `Literal` types together (python#103747)
  pythongh-103765: Fix 'Warning: py:class reference target not found: ModuleSpec' (pythonGH-103769)
  pythongh-87452: Improve the Popen.returncode docs
  Removed unnecessary escaping of asterisks (python#103714)
  pythonGH-102973: Slim down Fedora packages in the dev container (python#103283)
  pythongh-103091: Add PyUnstable_Type_AssignVersionTag (python#103095)
  ...
@lysnikolaou
Copy link
Contributor Author

Resolved in #103775.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants