summaryrefslogtreecommitdiff
path: root/tests/functional/u/used/used_before_assignment.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/u/used/used_before_assignment.py')
-rw-r--r--tests/functional/u/used/used_before_assignment.py62
1 files changed, 60 insertions, 2 deletions
diff --git a/tests/functional/u/used/used_before_assignment.py b/tests/functional/u/used/used_before_assignment.py
index d36b2fd8d..9b7d668ca 100644
--- a/tests/functional/u/used/used_before_assignment.py
+++ b/tests/functional/u/used/used_before_assignment.py
@@ -1,6 +1,6 @@
"""Miscellaneous used-before-assignment cases"""
# pylint: disable=consider-using-f-string, missing-function-docstring
-
+import datetime
MSG = "hello %s" % MSG # [used-before-assignment]
@@ -14,6 +14,17 @@ def outer():
outer()
+class ClassWithProperty: # pylint: disable=too-few-public-methods
+ """This test depends on earlier and later defined module-level functions."""
+ prop = property(redefine_time_import) # [used-before-assignment]
+ prop_defined_earlier = property(outer)
+
+
+calculate(1.01, 2) # [used-before-assignment]
+def calculate(value1: int, value2: float) -> int:
+ return value1 + value2
+
+
# pylint: disable=unused-import, wrong-import-position, import-outside-toplevel, reimported, redefined-outer-name, global-statement
import time
def redefine_time_import():
@@ -108,7 +119,7 @@ for num in [0, 1]:
print(VAR12)
def turn_on2(**kwargs):
- """https://github.com/PyCQA/pylint/issues/7873"""
+ """https://github.com/pylint-dev/pylint/issues/7873"""
if "brightness" in kwargs:
brightness = kwargs["brightness"]
var, *args = (1, "set_dimmer_state", brightness)
@@ -116,3 +127,50 @@ def turn_on2(**kwargs):
var, *args = (1, "restore_dimmer_state")
print(var, *args)
+
+
+# Variables guarded by the same test when used.
+
+# Always false
+if __name__ == "__main__":
+ PERCENT = 20
+ SALE = True
+
+if __name__ == "__main__":
+ print(PERCENT)
+
+# Different test
+if __name__ is None:
+ print(SALE) # [used-before-assignment]
+
+
+# Ambiguous, but same test
+if not datetime.date.today():
+ WAS_TODAY = True
+
+if not datetime.date.today():
+ print(WAS_TODAY)
+
+
+# Different tests but same inferred values
+# Need falsy values here
+def give_me_zero():
+ return 0
+
+def give_me_nothing():
+ return 0
+
+if give_me_zero():
+ WE_HAVE_ZERO = True
+ ALL_DONE = True
+
+if give_me_nothing():
+ print(WE_HAVE_ZERO)
+
+
+# Different tests, different values
+def give_me_none():
+ return None
+
+if give_me_none():
+ print(ALL_DONE) # [used-before-assignment]