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.

newstyle_properties.py 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # pylint: disable=too-few-public-methods
  2. """Test properties on old style classes and property.setter/deleter usage"""
  3. def getter(self):
  4. """interesting"""
  5. return self
  6. class CorrectClass(object):
  7. """correct usage"""
  8. method = property(getter, doc='hop')
  9. class OldStyleClass: # <3.0:[old-style-class]
  10. """bad usage"""
  11. method = property(getter, doc='hop') # <3.0:[property-on-old-class]
  12. def __init__(self):
  13. pass
  14. def decorator(func):
  15. """Redefining decorator."""
  16. def wrapped(self):
  17. """Wrapper function."""
  18. return func(self)
  19. return wrapped
  20. class SomeClass(object):
  21. """another docstring"""
  22. def __init__(self):
  23. self._prop = None
  24. @property
  25. def prop(self):
  26. """I'm the 'prop' property."""
  27. return self._prop
  28. @prop.setter
  29. def prop(self, value):
  30. """I'm the 'prop' property."""
  31. self._prop = value
  32. @prop.deleter
  33. def prop(self):
  34. """I'm the 'prop' property."""
  35. del self._prop
  36. @decorator
  37. def noregr(self):
  38. """Just a normal method with a decorator."""
  39. return self.prop