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

Use walrus operator for env-assignment syntax #77

Open
Technologicat opened this issue Jun 9, 2021 · 0 comments
Open

Use walrus operator for env-assignment syntax #77

Technologicat opened this issue Jun 9, 2021 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@Technologicat
Copy link
Owner

Technologicat commented Jun 9, 2021

Now that Python 3.8 has added the walrus operator :=, it would make more sense to override that (instead of left-shift <<) to indicate env-assignment in let, do, and similar constructs. It would also help make IDEs happy, because := is a name-binding operator also in standard Python.

The rules would remain the same they are now (as of v0.14.3 and v0.15.0): when a name := value operation is encountered, if the context allows an env-assignment, then it is an env-assignment; otherwise leave it unprocessed, delegating to the standard meaning of := (just like we now, somewhat less sensibly, delegate to the standard meaning of <<).

Doing this will remove the need for noqa: F821 for names declared in let and do expressions, as well as allow the Lispy dialect (variant of Lispython) to work without triggering any undefined-name errors in static code analyzers for standard Python, such as flake8.

We could add name := value now as an alternative syntax, and deprecate the old syntax name << value once Python 3.8 becomes the minimum supported version. See #1 for the language version support schedule.

Note to self: To get started on this, grep the codebase for envassign and LShift. These are already handled centrally, so the required changes should be rather minor. We have a version-sensitive wrapper for NamedExpr in unpythonic.syntax.astcompat that will simply not match anything in 3.6 and 3.7.

@Technologicat Technologicat added the enhancement New feature or request label Jun 9, 2021
@Technologicat Technologicat added this to the 0.15.x milestone Jun 9, 2021
@Technologicat Technologicat modified the milestones: 0.15.x, 0.15.1 Jun 22, 2021
@Technologicat Technologicat modified the milestones: 0.15.1, 0.15.2 Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant