diff options
Diffstat (limited to 'tests/functional/u/used/used_before_assignment.py')
-rw-r--r-- | tests/functional/u/used/used_before_assignment.py | 51 |
1 files changed, 49 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..91212612d 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] @@ -108,7 +108,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 +116,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] |