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

[#3791] propose a fix #4737

Merged
merged 4 commits into from Jul 22, 2021
Merged

[#3791] propose a fix #4737

merged 4 commits into from Jul 22, 2021

Conversation

rr-
Copy link
Contributor

@rr- rr- commented Jul 22, 2021

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

This is a proposed fix for an issue where defining a function decorated with a list comprehension that shares argument name, and the argument is used twice in the list comprehension, it shows an undefined-variable error.

To put it in code:

def decorator(seq):
    return lambda f: f

@decorator(x * x for x in "123")
def func(x):
    pass

This wrongfully shows an undefined-variable error since version at least 2.7.

def decorator(seq):
    return lambda f: f

@decorator(x for x in "123")
def func(x):
   pass

This is rightfully OK on the current main.

This probably will need changes, but I am not familiar enough with the codebase to go better about it.

Type of Changes

Type
βœ“ πŸ› Bug fix

Related Issue

Closes #3791

@coveralls
Copy link

coveralls commented Jul 22, 2021

Coverage Status

Coverage increased (+0.06%) to 92.154% when pulling d987fe0 on rr-:issue_3791 into 31aa6fd on PyCQA:main.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good thank you for the analysis, I have a small comment but this looks mergeable already.

@@ -1015,6 +1016,12 @@ def visit_name(self, node):
self._loopvar_name(node, name)
break

# the name has already been consumed, skip decorators
if name in current_consumer.consumed and utils.is_func_decorator(
current_consumer.node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be an or line 1012 instead :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, moved

CONTRIBUTORS.txt Outdated
@@ -1,4 +1,4 @@
ο»ΏContributors
Contributors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a modification here, I don't know why ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a guess but I think my editor ate the byte order mark?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was it. Restored :)

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.6 milestone Jul 22, 2021
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

@Pierre-Sassoulas Pierre-Sassoulas added Bug πŸͺ² False Positive 🦟 A message is emitted but nothing is wrong with the code labels Jul 22, 2021
@Pierre-Sassoulas Pierre-Sassoulas merged commit a054796 into pylint-dev:main Jul 22, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you for the fix and congratulation on becoming a pylint contributor :) !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug πŸͺ² False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive undefined-variable when variable name in decoration matches function argument
3 participants