diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-12-25 04:20:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-25 10:20:53 +0100 |
commit | e6f0bc5d32965eef37e498e15f05914d4275afb5 (patch) | |
tree | d30acf850b4c0d14252f99e7700357a747a84be3 /tests | |
parent | 4a5f5be479952d5c865a18520f14db321d2432b2 (diff) | |
download | pylint-git-e6f0bc5d32965eef37e498e15f05914d4275afb5.tar.gz |
Fix `used-before-assignment` if conditional imports guarded again when used (#7980)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/u/used/used_before_assignment_typing.py | 7 | ||||
-rw-r--r-- | tests/functional/u/used/used_before_assignment_typing.txt | 10 |
2 files changed, 12 insertions, 5 deletions
diff --git a/tests/functional/u/used/used_before_assignment_typing.py b/tests/functional/u/used/used_before_assignment_typing.py index c374b1a67..c0cb484e0 100644 --- a/tests/functional/u/used/used_before_assignment_typing.py +++ b/tests/functional/u/used/used_before_assignment_typing.py @@ -8,6 +8,7 @@ if TYPE_CHECKING: if True: # pylint: disable=using-constant-test import math import datetime + from urllib.request import urlopen class MyClass: """Type annotation or default values for first level methods can't refer to their own class""" @@ -101,3 +102,9 @@ class VariableAnnotationsGuardedByTypeChecking: # pylint: disable=too-few-publi def print_date(self, date) -> None: date: datetime.date = date print(date) + + +class ConditionalImportGuardedWhenUsed: # pylint: disable=too-few-public-methods + """Conditional imports also guarded by TYPE_CHECKING when used.""" + if TYPE_CHECKING: + print(urlopen) diff --git a/tests/functional/u/used/used_before_assignment_typing.txt b/tests/functional/u/used/used_before_assignment_typing.txt index 7d3223f4a..680c3430d 100644 --- a/tests/functional/u/used/used_before_assignment_typing.txt +++ b/tests/functional/u/used/used_before_assignment_typing.txt @@ -1,5 +1,5 @@ -undefined-variable:16:21:16:28:MyClass.incorrect_typing_method:Undefined variable 'MyClass':UNDEFINED -undefined-variable:21:26:21:33:MyClass.incorrect_nested_typing_method:Undefined variable 'MyClass':UNDEFINED -undefined-variable:26:20:26:27:MyClass.incorrect_default_method:Undefined variable 'MyClass':UNDEFINED -used-before-assignment:87:35:87:39:MyFourthClass.is_close:Using variable 'math' before assignment:HIGH -used-before-assignment:99:20:99:28:VariableAnnotationsGuardedByTypeChecking:Using variable 'datetime' before assignment:HIGH +undefined-variable:17:21:17:28:MyClass.incorrect_typing_method:Undefined variable 'MyClass':UNDEFINED +undefined-variable:22:26:22:33:MyClass.incorrect_nested_typing_method:Undefined variable 'MyClass':UNDEFINED +undefined-variable:27:20:27:27:MyClass.incorrect_default_method:Undefined variable 'MyClass':UNDEFINED +used-before-assignment:88:35:88:39:MyFourthClass.is_close:Using variable 'math' before assignment:HIGH +used-before-assignment:100:20:100:28:VariableAnnotationsGuardedByTypeChecking:Using variable 'datetime' before assignment:HIGH |