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

New check: Walrus operator recommended #4862

Closed
nickdrozd opened this issue Aug 17, 2021 · 3 comments · Fixed by #4876
Closed

New check: Walrus operator recommended #4862

nickdrozd opened this issue Aug 17, 2021 · 3 comments · Fixed by #4876
Assignees
Labels
Enhancement Improvement to a component Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors python 3.8 topic-assignment-expression Related to the walrus operator / assignment expression
Milestone

Comments

@nickdrozd
Copy link
Collaborator

Current problem

Consider this still-common pattern:

match = re.match(regex, string)
if match:
    do_stuff(match)

Desired solution

As of Python 3.8, this can be rewritten with the "walrus":

if (match := re.match(regex, string)):
    do_stuff(match)

Pylint should recommend using the walrus operator in situations like this.

Additional context

See https://www.python.org/dev/peps/pep-0572/

@nickdrozd nickdrozd added Enhancement Improvement to a component Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 17, 2021
@Pierre-Sassoulas Pierre-Sassoulas added python 3.8 Help wanted 🙏 Outside help would be appreciated, good for new contributors Good first issue Friendly and approachable by new contributors and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 18, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you, nice suggestion !

@cdce8p cdce8p added the topic-assignment-expression Related to the walrus operator / assignment expression label Aug 18, 2021
@cdce8p cdce8p self-assigned this Aug 19, 2021
@cdce8p cdce8p added this to the 2.10.0 milestone Aug 19, 2021
@cdce8p
Copy link
Member

cdce8p commented Aug 19, 2021

Opened a PR for it: #4876

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.10.0, 2.11.0 Aug 20, 2021
@Pierre-Sassoulas
Copy link
Member

Moving to 2.11 as I feel we already have a lot of things in 2.10 and we're sitting on great unreleased performance improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvement to a component Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors python 3.8 topic-assignment-expression Related to the walrus operator / assignment expression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants