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.

undefined_variable_py30.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """Test warnings about access to undefined variables
  2. for various Python 3 constructs. """
  3. # pylint: disable=too-few-public-methods, no-init, no-self-use
  4. # pylint: disable=wrong-import-position, invalid-metaclass
  5. class Undefined:
  6. """ test various annotation problems. """
  7. def test(self)->Undefined: # [undefined-variable]
  8. """ used Undefined, which is Undefined in this scope. """
  9. Undefined = True
  10. def test1(self)->Undefined:
  11. """ This Undefined exists at local scope. """
  12. def test2(self):
  13. """ This should not emit. """
  14. def func()->Undefined:
  15. """ empty """
  16. return
  17. return func
  18. class Undefined1:
  19. """ Other annotation problems. """
  20. Undef = 42
  21. ABC = 42
  22. class InnerScope:
  23. """ Test inner scope definition. """
  24. def test_undefined(self)->Undef: # [undefined-variable]
  25. """ Looking at a higher scope is impossible. """
  26. def test1(self)->ABC: # [undefined-variable]
  27. """ Triggers undefined-variable. """
  28. class FalsePositive342(object):
  29. # pylint: disable=line-too-long
  30. """ Fix some false positives found in
  31. https://bitbucket.org/logilab/pylint/issue/342/spurious-undefined-variable-for-class
  32. """
  33. top = 42
  34. def test_good(self, bac: top):
  35. """ top is defined at this moment. """
  36. def test_bad(self, bac: trop): # [undefined-variable]
  37. """ trop is undefined at this moment. """
  38. def test_bad1(self, *args: trop1): # [undefined-variable]
  39. """ trop1 is undefined at this moment. """
  40. def test_bad2(self, **bac: trop2): # [undefined-variable]
  41. """ trop2 is undefined at this moment. """
  42. from abc import ABCMeta
  43. class Bad(metaclass=ABCMet): # [undefined-variable]
  44. """ Notice the typo """
  45. class SecondBad(metaclass=ab.ABCMeta): # [undefined-variable]
  46. """ Notice the `ab` module. """
  47. class Good(metaclass=int):
  48. """ int is not a proper metaclass, but it is defined. """
  49. class SecondGood(metaclass=Good):
  50. """ empty """
  51. class ThirdGood(metaclass=ABCMeta):
  52. """ empty """
  53. class FourthGood(ThirdGood):
  54. """ This should not trigger anything. """
  55. # The following used to raise used-before-assignment
  56. # pylint: disable=missing-docstring, multiple-statements
  57. def used_before_assignment(*, arg): return arg + 1