Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

used_before_assignment_nonlocal.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """Check for nonlocal and used-before-assignment"""
  2. # pylint: disable=missing-docstring, unused-variable, no-init, too-few-public-methods
  3. __revision__ = 0
  4. def test_ok():
  5. """ uses nonlocal """
  6. cnt = 1
  7. def wrap():
  8. nonlocal cnt
  9. cnt = cnt + 1
  10. wrap()
  11. def test_fail():
  12. """ doesn't use nonlocal """
  13. cnt = 1
  14. def wrap():
  15. cnt = cnt + 1 # [used-before-assignment]
  16. wrap()
  17. def test_fail2():
  18. """ use nonlocal, but for other variable """
  19. cnt = 1
  20. count = 1
  21. def wrap():
  22. nonlocal count
  23. cnt = cnt + 1 # [used-before-assignment]
  24. wrap()
  25. def test_fail3(arg: test_fail4): # [used-before-assignment]
  26. """ Depends on `test_fail4`, in argument annotation. """
  27. return arg
  28. # +1: [used-before-assignment, used-before-assignment]
  29. def test_fail4(*args: test_fail5, **kwargs: undefined):
  30. """ Depends on `test_fail5` and `undefined` in
  31. variable and named arguments annotations.
  32. """
  33. return args, kwargs
  34. def test_fail5()->undefined1: # [used-before-assignment]
  35. """ Depends on `undefined1` in function return annotation. """
  36. def undefined():
  37. """ no op """
  38. def undefined1():
  39. """ no op """