A small quality-of-life improvement would be if the default format string included the name attribute by default.
>>> t = Timer('foobar')
>>> t.start()
>>> time.sleep(1)
>>> t.stop()
foobar elapsed time: 1.000 seconds
>>> t = Timer()
>>> t.start()
>>> time.sleep(1)
>>> t.stop()
Elapsed time: 1.000 seconds
This might be achieved with the following __post_init__ function:
def __post_init__(self):
if self.name is None:
self.text = "Elapsed time: {:0.4f} seconds"
else:
self.text = "{name} elapsed time {:0.4f} seconds"
Alternatively, name could just have a non-None default value (e.g. "Timer" or "Elapsed").
A small quality-of-life improvement would be if the default format string included the name attribute by default.
This might be achieved with the following
__post_init__function:Alternatively, name could just have a non-None default value (e.g. "Timer" or "Elapsed").