3 ms·
I've been experimenting with annotations to chain a set of functions together using a common namespace. In a nutshell, ns.register(foo: int, bar: int)
by ben509 8y ago
I've been experimenting with annotations to chain a set of functions together using a common namespace. In a nutshell,
ns.register(foo: int, bar: int)
@ns
def add_one(foo : ns.foo) -> ns.bar:
return foo + 1
It gets a good bit more complicated than this, but when you've got a whole mess of functions to chain together, this lets you do it _reasonably_ sanely and figure out the ordering.
I think it should be possible to be compatible with a type checker like mypy as it could reannotate the decorated function with the types looked up from the namespace, but I haven't tested that.