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.

inherit_non_class.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """Test that inheriting from something which is not
  2. a class emits a warning. """
  3. # pylint: disable=no-init, import-error, invalid-name, using-constant-test
  4. # pylint: disable=missing-docstring, too-few-public-methods, no-absolute-import
  5. from missing import Missing
  6. if 1:
  7. Ambiguous = None
  8. else:
  9. Ambiguous = int
  10. class Empty(object):
  11. """ Empty class. """
  12. def return_class():
  13. """ Return a class. """
  14. return Good3
  15. class Bad(1): # [inherit-non-class]
  16. """ Can't inherit from instance. """
  17. class Bad1(lambda abc: 42): # [inherit-non-class]
  18. """ Can't inherit from lambda. """
  19. class Bad2(object()): # [inherit-non-class]
  20. """ Can't inherit from an instance of object. """
  21. class Bad3(return_class): # [inherit-non-class]
  22. """ Can't inherit from function. """
  23. class Bad4(Empty()): # [inherit-non-class]
  24. """ Can't inherit from instance. """
  25. class Good(object):
  26. pass
  27. class Good1(int):
  28. pass
  29. class Good2(type):
  30. pass
  31. class Good3(type(int)):
  32. pass
  33. class Good4(return_class()):
  34. pass
  35. class Good5(Good4, int, object):
  36. pass
  37. class Good6(Ambiguous):
  38. """ Inherits from something ambiguous.
  39. This could emit a warning when we will have
  40. flow detection.
  41. """
  42. class Unknown(Missing):
  43. pass
  44. class Unknown1(Good5 if True else Bad1):
  45. pass
  46. class NotInheritableBool(bool): # [inherit-non-class]
  47. pass
  48. class NotInheritableRange(range): # [inherit-non-class]
  49. pass
  50. class NotInheritableSlice(slice): # [inherit-non-class]
  51. pass
  52. class NotInheritableMemoryView(memoryview): # [inherit-non-class]
  53. pass