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.

class_members_py30.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """ Various tests for class members access. """
  2. # pylint: disable=R0903,import-error,no-init,missing-docstring, wrong-import-position,wrong-import-order
  3. from missing import Missing
  4. class MyClass(object):
  5. """class docstring"""
  6. def __init__(self):
  7. """init"""
  8. self.correct = 1
  9. def test(self):
  10. """test"""
  11. self.correct += 2
  12. self.incorrect += 2 # [no-member]
  13. del self.havenot # [no-member]
  14. self.nonexistent1.truc() # [no-member]
  15. self.nonexistent2[1] = 'hehe' # [no-member]
  16. class XYZMixin(object):
  17. """access to undefined members should be ignored in mixin classes by
  18. default
  19. """
  20. def __init__(self):
  21. print(self.nonexistent)
  22. class NewClass(object):
  23. """use object.__setattr__"""
  24. def __init__(self):
  25. self.__setattr__('toto', 'tutu')
  26. from abc import ABCMeta
  27. class TestMetaclass(object, metaclass=ABCMeta):
  28. """ Test attribute access for metaclasses. """
  29. class Metaclass(type):
  30. """ metaclass """
  31. @classmethod
  32. def test(mcs):
  33. """ classmethod """
  34. class UsingMetaclass(object, metaclass=Metaclass):
  35. """ empty """
  36. TestMetaclass.register(int)
  37. UsingMetaclass.test()
  38. TestMetaclass().register(int) # [no-member]
  39. UsingMetaclass().test() # [no-member]
  40. class NoKnownBases(Missing):
  41. """Don't emit no-member if we don't know the bases of a class."""
  42. NoKnownBases().lalala()
  43. class MetaClass(object):
  44. """Look some methods in the implicit metaclass."""
  45. @classmethod
  46. def whatever(cls):
  47. return cls.mro() + cls.missing() # [no-member]
  48. from collections import namedtuple
  49. Tuple = namedtuple("Tuple", "field other")
  50. Tuple.field.__doc__ = "A doc for the field."