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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CONTRIBUTORS.txt
@@ -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 :)

------------

Current team:
Expand Down Expand Up @@ -519,3 +519,5 @@ contributors:
- Documented Jupyter integration

* Yilei Yang: contributor

* Marcin Kurczewski (rr-): contributor
7 changes: 7 additions & 0 deletions pylint/checkers/variables.py
Expand Up @@ -44,6 +44,7 @@
# Copyright (c) 2021 Lorena B <46202743+lorena-b@users.noreply.github.com>
# Copyright (c) 2021 haasea <44787650+haasea@users.noreply.github.com>
# Copyright (c) 2021 Alexander Kapshuna <kapsh@kap.sh>
# Copyright (c) 2021 Marcin Kurczewski <rr-@sakuya.pl>

# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
Expand Down Expand Up @@ -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

):
break

found_node = current_consumer.get_next_to_consume(node)
if found_node is None:
continue
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/u/undefined/undefined_variable.py
Expand Up @@ -309,3 +309,22 @@ def undefined_annotation(a:x): # [undefined-variable]
]
for item in lst
]


# 3791
@decorator(x for x in range(3))
def decorated1(x):
print(x)

@decorator(x * x for x in range(3))
def decorated2(x):
print(x)

@decorator(x) # [undefined-variable]
@decorator(x * x for x in range(3))
def decorated3(x):
print(x)

@decorator(x * x * y for x in range(3)) # [undefined-variable]
def decorated4(x):
print(x)
2 changes: 2 additions & 0 deletions tests/functional/u/undefined/undefined_variable.txt
Expand Up @@ -28,3 +28,5 @@ used-before-assignment:254:26:func_should_fail:Using variable 'datetime' before
undefined-variable:281:18:not_using_loop_variable_accordingly:Undefined variable 'iteree'
undefined-variable:292:27:undefined_annotation:Undefined variable 'x'
used-before-assignment:293:7:undefined_annotation:Using variable 'x' before assignment
undefined-variable:323:11:decorated3:Undefined variable 'x'
undefined-variable:328:19:decorated4:Undefined variable 'y'