Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typechecking functions accepting classes (as opposed to instances) #10

Open
mejedi opened this issue Dec 31, 2014 · 2 comments
Open

Typechecking functions accepting classes (as opposed to instances) #10

mejedi opened this issue Dec 31, 2014 · 2 comments

Comments

@mejedi
Copy link

mejedi commented Dec 31, 2014

A little feature request here: it would be great if it was possible to validate a class passed via function parameter using issubclass().

@senko
Copy link
Member

senko commented Jan 1, 2015

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?

@mejedi
Copy link
Author

mejedi commented Jan 7, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants