Misleading SyntaxError: cannot use assignment expressions with lambda
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
Python 3.12.8 (tags/v3.12.8:2dc476b, Dec 3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> lambda x: foo := 2
File "<stdin>", line 1
lambda x: foo := 2
^^^^^^^^^^^^^
SyntaxError: cannot use assignment expressions with lambda
>>> lambda x: (foo := 2)
<function <lambda> at 0x00000229CC40E0C0>
IIRC, until today I believed that you could never use an assignment expression in a lambda. I was disabused of this notion only by reading PEP 572 itself. I believe the SyntaxError should ideally read something along the lines of "cannot use unparenthesized assignment expressions with lambda".
I wasn't sure to what category to file this under exactly, sorry if I chose wrong.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia cercando in CPython la diagnosi esatta "cannot use assignment expressions with lambda" e verifica la gestione correlata nel parser o nel compilatore, usando PEP 572 come contesto. Riproduci entrambi gli esempi di lambda del report; il lavoro è completato quando la forma senza parentesi segnala la restrizione più precisa, mentre la forma tra parentesi continua a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100