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.

membership_protocol.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # pylint: disable=missing-docstring,pointless-statement,expression-not-assigned,too-few-public-methods,import-error,no-init,wrong-import-position,no-else-return
  2. # standard types
  3. 1 in [1, 2, 3]
  4. 1 in {'a': 1, 'b': 2}
  5. 1 in {1, 2, 3}
  6. 1 in (1, 2, 3)
  7. '1' in "123"
  8. '1' in u"123"
  9. '1' in bytearray(b"123")
  10. 1 in frozenset([1, 2, 3])
  11. # comprehensions
  12. 1 in [x ** 2 % 10 for x in range(10)]
  13. 1 in {x ** 2 % 10 for x in range(10)}
  14. 1 in {x: x ** 2 % 10 for x in range(10)}
  15. # iterators
  16. 1 in iter([1, 2, 3])
  17. # generator
  18. def count(upto=float("inf")):
  19. i = 0
  20. while True:
  21. if i > upto:
  22. break
  23. yield i
  24. i += 1
  25. 10 in count(upto=10)
  26. # custom instance
  27. class UniversalContainer(object):
  28. def __contains__(self, key):
  29. return True
  30. 42 in UniversalContainer()
  31. # custom iterable
  32. class CustomIterable(object):
  33. def __iter__(self):
  34. return iter((1, 2, 3))
  35. 3 in CustomIterable()
  36. # old-style iterable
  37. class OldStyleIterable(object):
  38. def __getitem__(self, key):
  39. if key < 10:
  40. return 2 ** key
  41. else:
  42. raise IndexError("bad index")
  43. 64 in OldStyleIterable()
  44. # do not emit warning if class has unknown bases
  45. from some_missing_module import ImportedClass
  46. class MaybeIterable(ImportedClass):
  47. pass
  48. 10 in MaybeIterable()
  49. # do not emit warning inside mixins/abstract/base classes
  50. class UsefulMixin(object):
  51. stuff = None
  52. def get_stuff(self):
  53. return self.stuff
  54. def act(self, thing):
  55. stuff = self.get_stuff()
  56. if thing in stuff:
  57. pass
  58. class BaseThing(object):
  59. valid_values = None
  60. def validate(self, value):
  61. if self.valid_values is None:
  62. return True
  63. else:
  64. # error should not be emitted here
  65. return value in self.valid_values
  66. class AbstractThing(object):
  67. valid_values = None
  68. def validate(self, value):
  69. if self.valid_values is None:
  70. return True
  71. else:
  72. # error should not be emitted here
  73. return value in self.valid_values
  74. # class is not named as abstract
  75. # but still is deduceably abstract
  76. class Thing(object):
  77. valid_values = None
  78. def __init__(self):
  79. self._init_values()
  80. def validate(self, value):
  81. if self.valid_values is None:
  82. return True
  83. else:
  84. # error should not be emitted here
  85. return value in self.valid_values
  86. def _init_values(self):
  87. raise NotImplementedError
  88. # error cases
  89. 42 in 42 # [unsupported-membership-test]
  90. 42 not in None # [unsupported-membership-test]
  91. 42 in 8.5 # [unsupported-membership-test]
  92. class EmptyClass(object):
  93. pass
  94. 42 not in EmptyClass() # [unsupported-membership-test]
  95. 42 in EmptyClass # [unsupported-membership-test]
  96. 42 not in count # [unsupported-membership-test]
  97. 42 in range # [unsupported-membership-test]