summaryrefslogtreecommitdiff
path: root/tests/functional
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-03-30 21:29:58 -0400
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-03-31 09:44:48 +0200
commit881262641ee1ca6fd6704b66b2b4ae37597e8fef (patch)
tree18c6a319c8474c7bd63fc5bad9b5a1cbaa8bfa86 /tests/functional
parent5ea03af1268ae4776e8ddd9dc55e14f465710288 (diff)
downloadpylint-git-881262641ee1ca6fd6704b66b2b4ae37597e8fef.tar.gz
Remove assumption of direct parentage in `used-before-assignment` homonym handling
The previous fixes for false positives involving homonyms with variables in comprehension tests in #5586 and #5817 still relied on assumptions of direct parentage.
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/u/used/used_before_assignment_filtered_comprehension.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/functional/u/used/used_before_assignment_filtered_comprehension.py b/tests/functional/u/used/used_before_assignment_filtered_comprehension.py
index f638b0be9..f0c569aad 100644
--- a/tests/functional/u/used/used_before_assignment_filtered_comprehension.py
+++ b/tests/functional/u/used/used_before_assignment_filtered_comprehension.py
@@ -7,3 +7,45 @@ def func():
except ZeroDivisionError:
value = 1
print(value)
+
+
+def func2():
+ """Same, but with attribute access."""
+ try:
+ print(value for value in range(1 / 0) if isinstance(value.num, int))
+ except ZeroDivisionError:
+ value = 1
+ print(value)
+
+
+def func3():
+ """Same, but with no call."""
+ try:
+ print(value for value in range(1 / 0) if value)
+ except ZeroDivisionError:
+ value = 1
+ print(value)
+
+
+def func4():
+ """https://github.com/PyCQA/pylint/issues/6035"""
+ assets = [asset for asset in range(3) if asset.name == "filename"]
+
+ try:
+ raise ValueError
+ except ValueError:
+ asset = assets[0]
+ print(asset)
+
+
+def func5():
+ """Similar, but with subscript notation"""
+ results = {}
+ # pylint: disable-next=consider-using-dict-items
+ filtered = [k for k in results if isinstance(results[k], dict)]
+
+ try:
+ 1 / 0
+ except ZeroDivisionError:
+ k = None
+ print(k, filtered)