fork download
  1. def decorator_factory(type_):
  2. def decorator(cls):
  3. cls.contaVarClasse = sum(
  4. isinstance(value, type_)
  5. for name, value in vars(cls).items()
  6. if not (name.startswith('__') and name.endswith('__'))
  7. )
  8. return cls
  9. return decorator
  10.  
  11. @decorator_factory(str)
  12. class MyClass:
  13. countme = "b"
  14. notme = 2
  15.  
  16. def __init__(self):
  17. self.dontcountme = "a"
  18. self.norme = 5
  19.  
  20. print(MyClass.contaVarClasse)
  21.  
Success #stdin #stdout 0.04s 9572KB
stdin
Standard input is empty
stdout
1