PageRenderTime 61ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/venv/Lib/site-packages/pylint/test/functional/super_checks.py

https://bitbucket.org/DennD/djangoember
Python | 125 lines | 98 code | 12 blank | 15 comment | 0 complexity | ad500b0af1fc14c8b12decf6690fd775 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # pylint: disable=too-few-public-methods,import-error, no-absolute-import,missing-docstring
  2. # pylint: disable=useless-super-delegation,wrong-import-position,invalid-name, wrong-import-order
  3. from unknown import Missing
  4. class Aaaa: # <3.0:[old-style-class]
  5. """old style"""
  6. def hop(self): # <3.0:[super-on-old-class]
  7. """hop"""
  8. super(Aaaa, self).hop() # >=3.0:[no-member]
  9. def __init__(self): # <3.0:[super-on-old-class]
  10. super(Aaaa, self).__init__()
  11. class NewAaaa(object):
  12. """old style"""
  13. def hop(self):
  14. """hop"""
  15. super(NewAaaa, self).hop() # [no-member]
  16. def __init__(self):
  17. super(Aaaa, self).__init__() # [bad-super-call]
  18. class Py3kAaaa(NewAaaa):
  19. """new style"""
  20. def __init__(self):
  21. super().__init__() # <3.0:[missing-super-argument]
  22. class Py3kWrongSuper(Py3kAaaa):
  23. """new style"""
  24. def __init__(self):
  25. super(NewAaaa, self).__init__() # [bad-super-call]
  26. class WrongNameRegression(Py3kAaaa):
  27. """ test a regression with the message """
  28. def __init__(self):
  29. super(Missing, self).__init__() # [bad-super-call]
  30. class Getattr(object):
  31. """ crash """
  32. name = NewAaaa
  33. class CrashSuper(object):
  34. """ test a crash with this checker """
  35. def __init__(self):
  36. super(Getattr.name, self).__init__() # [bad-super-call]
  37. class Empty(object):
  38. """Just an empty class."""
  39. class SuperDifferentScope(object):
  40. """Don'emit bad-super-call when the super call is in another scope.
  41. For reference, see https://bitbucket.org/logilab/pylint/issue/403.
  42. """
  43. @staticmethod
  44. def test():
  45. """Test that a bad-super-call is not emitted for this case."""
  46. class FalsePositive(Empty):
  47. """The following super is in another scope than `test`."""
  48. def __init__(self, arg):
  49. super(FalsePositive, self).__init__(arg)
  50. super(object, 1).__init__() # [bad-super-call]
  51. class UnknownBases(Missing):
  52. """Don't emit if we don't know all the bases."""
  53. def __init__(self):
  54. super(UnknownBases, self).__init__()
  55. super(UnknownBases, self).test()
  56. super(Missing, self).test() # [bad-super-call]
  57. # Test that we are detecting proper super errors.
  58. class BaseClass(object):
  59. not_a_method = 42
  60. def function(self, param):
  61. return param + self.not_a_method
  62. def __getattr__(self, attr):
  63. return attr
  64. class InvalidSuperChecks(BaseClass):
  65. def __init__(self):
  66. super(InvalidSuperChecks, self).not_a_method() # [not-callable]
  67. super(InvalidSuperChecks, self).attribute_error() # [no-member]
  68. super(InvalidSuperChecks, self).function(42)
  69. super(InvalidSuperChecks, self).function() # [no-value-for-parameter]
  70. super(InvalidSuperChecks, self).function(42, 24, 24) # [too-many-function-args]
  71. # +1: [unexpected-keyword-arg,no-value-for-parameter]
  72. super(InvalidSuperChecks, self).function(lala=42)
  73. # Even though BaseClass has a __getattr__, that won't
  74. # be called.
  75. super(InvalidSuperChecks, self).attribute_error() # [no-member]
  76. # Regression for PyCQA/pylint/issues/773
  77. import subprocess
  78. # The problem was related to astroid not filtering statements
  79. # at scope level properly, basically not doing strong updates.
  80. try:
  81. TimeoutExpired = subprocess.TimeoutExpired
  82. except AttributeError:
  83. class TimeoutExpired(subprocess.CalledProcessError):
  84. def __init__(self):
  85. returncode = -1
  86. self.timeout = -1
  87. super(TimeoutExpired, self).__init__(returncode)
  88. class SuperWithType(object):
  89. """type(self) may lead to recursion loop in derived classes"""
  90. def __init__(self):
  91. super(type(self), self).__init__() # [bad-super-call]
  92. class SuperWithSelfClass(object):
  93. """self.__class__ may lead to recursion loop in derived classes"""
  94. def __init__(self):
  95. super(self.__class__, self).__init__() # [bad-super-call]