subclass_native_call.py 691 B

123456789101112131415161718192021222324252627282930
  1. # test calling a subclass of a native class that supports calling
  2. # For this test we need a native class that can be subclassed (has make_new)
  3. # and is callable (has call). The only one available is machine.Signal, which
  4. # in turns needs PinBase.
  5. try:
  6. import umachine as machine
  7. except ImportError:
  8. import machine
  9. try:
  10. machine.PinBase
  11. machine.Signal
  12. except AttributeError:
  13. print("SKIP")
  14. raise SystemExit
  15. class Pin(machine.PinBase):
  16. #def __init__(self):
  17. # self.v = 0
  18. def value(self, v=None):
  19. return 42
  20. class MySignal(machine.Signal):
  21. pass
  22. s = MySignal(Pin())
  23. # apply call to the subclass, which should call the native base
  24. print(s())