fork download
  1. import warnings
  2.  
  3. def warning_property(message, warning_type=DeprecationWarning):
  4. class _property(property):
  5. def __get__(self, obj, obj_type=None):
  6. value = super().__get__(obj, obj_type)
  7. class _proxy(type(value)):
  8. def __call__(self):
  9. warnings.warn(message, warning_type)
  10. return value
  11. return _proxy(value)
  12. return _property
  13.  
  14. class A:
  15. @warning_property(".length function is deprecated. Use the .length property")
  16. def length(self):
  17. return 1
  18.  
  19. print(A().length)
  20. print(A().length())# your code goes here
Success #stdin #stdout #stderr 0.03s 9852KB
stdin
Standard input is empty
stdout
1
1
stderr
./prog.py:9: DeprecationWarning: .length function is deprecated. Use the .length property