typedecorator
typedecorator copied to clipboard
Typechecking functions accepting classes (as opposed to instances)
A little feature request here: it would be great if it was possible to validate a class passed via function parameter using issubclass().
Thanks for the suggestion @mejedi . It certainly looks like a useful use-case. I'm trying to think of a good way to represent this check (as opposed to the instance chek) in the signature, any ideas?
It also might be possible to cover this use-case if #5 is implemented, so you could do arbitrary checks, eg:
def subclass(base):
return lambda cls: isinstance(cls, type) and issubclass(cls, base)
@params(cls=subclass(MyClass))
def myfunc(cls):
...
Thoughts?
Thoughts?
The library is already capable of expressing complex assertions in function signatures, I mean Nullable and Union. Extending this with a Class is probably not too ugly.