2 ms·
There exist libraries that provide 'duck types' and other goodness for type hinting. typecheck [0] is one (which can also run-time enforce the check) used like
by OJFord 10y ago
There exist libraries that provide 'duck types' and other goodness for type hinting.
typecheck [0] is one (which can also run-time enforce the check) used like:
import typecheck as tc
def logathing(
dest: tc.hasattrs('write'),
thing: tc.any(int, float, str),
prefix: tc.optional(str)=None
):
dest.write(prefix + str(thing) if prefix else str(thing))
[0] - https://github.com/prechelt/typecheck-decorator https://github.com/prechelt/typecheck-decorator