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
Support generic types in signature inspection #2640
Support generic types in signature inspection #2640
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out, and for the patch!
I'm going to ask for something a little more complicated, though: because type annotations aren't the only possible use of function argument annotations, we'll still need to check that the thing "is a type (semantically)". Fortunately we already have the helper function for that:
def is_a_type(thing): | |
"""Return True if thing is a type or a generic type like thing.""" | |
return isinstance(thing, type) or is_generic_type(thing) or is_a_new_type(thing) |
You'll probably need to import it locally inside the function though, to avoid import cycles. And then finally, we'll want a test that given e.g. def f(a: 1): ...
, we don't treat that annotation as a type.
17cbd90
to
d2ca4b8
Compare
Did not realise that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Two minor issues below; but you're pretty much done 😁
Most of the test failures are because Lark just released a new version which turns out to break our integration; I'll be fixing that in #2639 tomorrow.
Co-authored-by: Zac Hatfield-Dodds <Zac-HD@users.noreply.github.com>
718b85f
to
2b4291e
Compare
The code #2580 was taken from existing code that was intended for an older Python version which didn't take the
typing
module into account. This patch removes the check fortype
instance, to allow thetyping
types such asLiteral
,Union
, etc.As the signature is only manually created, I don't see an issue with the complete removal of the check. The alternative is to ensure it is from the
typing
module but I can't find an easy way to do this without using the private types.