-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Should we maybe thinks about allowing unparenthesized top-level assignment expressions. It came up on ipython/ipython#14214 that people would like to have something like that, especially in REPLs, in order to be able to assign a value to a variable and have it be displayed afterwards. I played around with the parser a bit and the change to allow this is very straight-forward.
We could also discuss adding it behind a flag or only enable it on the REPL.
Behavior on main:
❯ ./python.exe
Python 3.13.0a1+ (heads/main:baeb7718f8, Nov 10 2023, 12:05:38) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a := 3
File "<stdin>", line 1
a := 3
^^
SyntaxError: invalid syntax
New behavior:
❯ ./python.exe
Python 3.13.0a1+ (heads/main-dirty:baeb7718f8, Nov 10 2023, 12:20:20) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a := 3
3
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortype-featureA feature request or enhancementA feature request or enhancement