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.

abstract_class_instantiated_py2.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """Check that instantiating a class with
  2. `abc.ABCMeta` as metaclass fails if it defines
  3. abstract methods.
  4. """
  5. # pylint: disable=too-few-public-methods, missing-docstring
  6. # pylint: disable=no-absolute-import, metaclass-assignment
  7. # pylint: disable=abstract-method, import-error, wildcard-import
  8. import abc
  9. from abc import ABCMeta
  10. from lala import Bala
  11. class GoodClass(object):
  12. __metaclass__ = abc.ABCMeta
  13. class SecondGoodClass(object):
  14. __metaclass__ = abc.ABCMeta
  15. def test(self):
  16. """ do nothing. """
  17. class ThirdGoodClass(object):
  18. __metaclass__ = abc.ABCMeta
  19. def test(self):
  20. raise NotImplementedError()
  21. class FourthGoodClass(object):
  22. __metaclass__ = ABCMeta
  23. class BadClass(object):
  24. __metaclass__ = abc.ABCMeta
  25. @abc.abstractmethod
  26. def test(self):
  27. """ do nothing. """
  28. class SecondBadClass(object):
  29. __metaclass__ = abc.ABCMeta
  30. @property
  31. @abc.abstractmethod
  32. def test(self):
  33. """ do nothing. """
  34. class ThirdBadClass(object):
  35. __metaclass__ = ABCMeta
  36. @abc.abstractmethod
  37. def test(self):
  38. pass
  39. class FourthBadClass(ThirdBadClass):
  40. pass
  41. class SomeMetaclass(object):
  42. __metaclass__ = ABCMeta
  43. @abc.abstractmethod
  44. def prop(self):
  45. pass
  46. class FifthGoodClass(SomeMetaclass):
  47. """Don't consider this abstract if some attributes are
  48. there, but can't be inferred.
  49. """
  50. prop = Bala # missing
  51. def main():
  52. """ do nothing """
  53. GoodClass()
  54. SecondGoodClass()
  55. ThirdGoodClass()
  56. FourthGoodClass()
  57. BadClass() # [abstract-class-instantiated]
  58. SecondBadClass() # [abstract-class-instantiated]
  59. ThirdBadClass() # [abstract-class-instantiated]
  60. FourthBadClass() # [abstract-class-instantiated]