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

False positive? Syntax Error for a valid Python expression #600

Closed
qexat opened this issue Dec 22, 2024 · 2 comments
Closed

False positive? Syntax Error for a valid Python expression #600

qexat opened this issue Dec 22, 2024 · 2 comments

Comments

@qexat
Copy link

qexat commented Dec 22, 2024

Hi. First of all, thank you for building ptpython, it is amazing. It has been my go-to Python REPL coupled with my custom .pythonrc for a while now.

Now to the report:

>>> from __future__ import annotations
>>> x: (y := 5) = 3
[Syntax Error: named expression cannot be used within an annotation (<input>, line 1)]

The error does not show when the annotations feature is not present.

In my opinion, either the syntax error should not happen, or it should always occur, even when __future__.annotations is not enabled.

I searched the issue tracker with "named expression", "within an annotation" which did not yield any results.

Python: 3.12.7
ptpython: 3.0.29

@jonathanslenders
Copy link
Member

Hi @qexat,

This has little to do with ptpython, but more with how Python works and evaluates annotations. The native Python shell does the same:

 $ python3
Python 3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import annotations
>>> x: (y := 5) = 3
  File "<stdin>", line 1
SyntaxError: named expression cannot be used within an annotation
>>>

@qexat
Copy link
Author

qexat commented Jan 7, 2025

I can reproduce now - I originally opened the issue specifically because it somehow didn't happen with the default Python REPL at the time, not sure what was going on

@qexat qexat closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants