mirror of
https://github.com/micropython/micropython.git
synced 2026-04-29 12:20:12 +02:00
5ce74c3f7f
Signed-off-by: Angus Gratton <angus@redyak.com.au>
39 lines
925 B
Python
39 lines
925 B
Python
# test subclassing custom native class
|
|
|
|
try:
|
|
from cexample import AdvancedTimer
|
|
import time # used to skip this test on minimal unix variant
|
|
except ImportError:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
|
|
class SubTimer(AdvancedTimer):
|
|
def __init__(self):
|
|
# At this point, self does not yet represent a AdvancedTimer instance.
|
|
print(self)
|
|
|
|
# So lookups via type.attr handler will fail.
|
|
try:
|
|
self.seconds
|
|
except AttributeError:
|
|
print("AttributeError")
|
|
|
|
# Also applies to builtin methods.
|
|
try:
|
|
self.time()
|
|
except AttributeError:
|
|
print("AttributeError")
|
|
|
|
# Initialize base class.
|
|
super().__init__(self)
|
|
|
|
# Now you can access methods and attributes normally.
|
|
self.time()
|
|
print(self.seconds)
|
|
self.seconds = 123
|
|
print(self.seconds)
|
|
|
|
|
|
watch = SubTimer()
|