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_py27.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """ Various tests for class members access. """
  2. # pylint: disable=R0903,print-statement,no-absolute-import, metaclass-assignment,import-error,no-init,missing-docstring, wrong-import-order,wrong-import-position
  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):
  28. """ Test attribute access for metaclasses. """
  29. __metaclass__ = ABCMeta
  30. class Metaclass(type):
  31. """ metaclass """
  32. @classmethod
  33. def test(mcs):
  34. """ classmethod """
  35. class UsingMetaclass(object):
  36. """ empty """
  37. __metaclass__ = Metaclass
  38. TestMetaclass.register(int)
  39. UsingMetaclass.test()
  40. TestMetaclass().register(int) # [no-member]
  41. UsingMetaclass().test() # [no-member]
  42. class NoKnownBases(Missing):
  43. """Don't emit no-member if we don't know the bases of a class."""
  44. NoKnownBases().lalala()
  45. class MetaClass(object):
  46. """Look some methods in the implicit metaclass."""
  47. @classmethod
  48. def whatever(cls):
  49. return cls.mro() + cls.missing() # [no-member]
  50. from collections import namedtuple
  51. Tuple = namedtuple("Tuple", "field other")
  52. Tuple.field.__doc__ = "A doc for the field."