Skip to content

Commit 9297688

Browse files
authored
Merge branch 'main' into invalid-toml-config
2 parents 1b0c3e2 + a054796 commit 9297688

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

CONTRIBUTORS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,5 +520,7 @@ contributors:
520520

521521
* Yilei Yang: contributor
522522

523+
* Marcin Kurczewski (rr-): contributor
524+
523525
* Tanvi Moharir: contributor
524526
- Fix for invalid toml config

pylint/checkers/variables.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# Copyright (c) 2021 Lorena B <[email protected]>
4545
# Copyright (c) 2021 haasea <[email protected]>
4646
# Copyright (c) 2021 Alexander Kapshuna <[email protected]>
47+
# Copyright (c) 2021 Marcin Kurczewski <[email protected]>
4748

4849
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
4950
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
@@ -1006,9 +1007,12 @@ def visit_name(self, node):
10061007
# variable used outside the loop
10071008
# avoid the case where there are homonyms inside function scope and
10081009
# comprehension current scope (avoid bug #1731)
1009-
if name in current_consumer.consumed and not (
1010-
current_consumer.scope_type == "comprehension"
1011-
and self._has_homonym_in_upper_function_scope(node, i)
1010+
if name in current_consumer.consumed and (
1011+
utils.is_func_decorator(current_consumer.node)
1012+
or not (
1013+
current_consumer.scope_type == "comprehension"
1014+
and self._has_homonym_in_upper_function_scope(node, i)
1015+
)
10121016
):
10131017
defnode = utils.assign_parent(current_consumer.consumed[name][0])
10141018
self._check_late_binding_closure(node, defnode)

tests/functional/u/undefined/undefined_variable.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,22 @@ def undefined_annotation(a:x): # [undefined-variable]
309309
]
310310
for item in lst
311311
]
312+
313+
314+
# 3791
315+
@decorator(x for x in range(3))
316+
def decorated1(x):
317+
print(x)
318+
319+
@decorator(x * x for x in range(3))
320+
def decorated2(x):
321+
print(x)
322+
323+
@decorator(x) # [undefined-variable]
324+
@decorator(x * x for x in range(3))
325+
def decorated3(x):
326+
print(x)
327+
328+
@decorator(x * x * y for x in range(3)) # [undefined-variable]
329+
def decorated4(x):
330+
print(x)

tests/functional/u/undefined/undefined_variable.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ used-before-assignment:254:26:func_should_fail:Using variable 'datetime' before
2828
undefined-variable:281:18:not_using_loop_variable_accordingly:Undefined variable 'iteree'
2929
undefined-variable:292:27:undefined_annotation:Undefined variable 'x'
3030
used-before-assignment:293:7:undefined_annotation:Using variable 'x' before assignment
31+
undefined-variable:323:11:decorated3:Undefined variable 'x'
32+
undefined-variable:328:19:decorated4:Undefined variable 'y'

0 commit comments

Comments
 (0)