-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Fix detection of LanguageServer
type annotation when future annotations are used
#352
Conversation
The `Temp` test class must be moved to global variables for name resolution to succeed
Looks good ❤️ I'm happy to merge. But maybe @alcarney wants to give it a thumbs up too? |
@@ -49,7 +49,7 @@ def has_ls_param_or_annotation(f, annotation): | |||
try: | |||
sig = inspect.signature(f) | |||
first_p = next(itertools.islice(sig.parameters.values(), 0, 1)) | |||
return first_p.name == PARAM_LS or first_p.annotation is annotation | |||
return first_p.name == PARAM_LS or get_type_hints(f)[first_p.name] == annotation |
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.
Oh I changed from is
to ==
here by accident. I'm not sure is
is "proper" here but I also don't think it matters.
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.
Yeah, I feel like ==
is most often the right choice, so it's probably a good change.
Thank you 🙇 |
Better late than never! 😅 Looks good! |
Description
The following example fails on
main
because the annotation is a string rather than a concrete type due to the use offrom __future__ import annotations
.typing.get_type_hints
can be used to resolve the annotations for the signature to support detection in this case.This can also be reproduced by wrapping the annotation type in a string manually (as I do in the test in this pull request).
Code review checklist (for code reviewer to complete)
[ ] Docstrings have been included and/or updated, as appropriate[ ] Standalone docs have been updated accordingly