-
-
Notifications
You must be signed in to change notification settings - Fork 508
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 mypy annotations using Python 2 comment syntax #1002
Conversation
Thanks man! There's quite a few issues in the tests. Can you maybe rebase on master and try to fix them. Sorry for not replying sooner. But I was pretty busy :/ The general approach definitely makes sense and I'd be happy to review the remaining things again once we're sure that it's working :) |
ec7886e
to
b9903ed
Compare
Rebased. Almost all of the tests are passing, except Python 2.7 on JEDI_TEST_ENVIRONMENT=35 and 36:
It's not clear to me what's going on here. |
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.
Good stuff! There's basically this one thing you could still do about the parser. Everything else is coupled way more to the general infrastructure of jedi. Let me know if you're going to do this in the next few days or I'll just merge and do it myself.
Huge thanks for this work.
ValueError: malformed node or string: b"u'str'"
It's not clear to me what's going on here.
I will handle that. It has probably to do with the repr(str(
stuff that makes problems, because of unicode stuff.
['foo', 'Bar[baz, biz]']. | ||
|
||
""" | ||
node = parse(decl_text).children[0] |
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.
Here we need to handle the error cases. Please add a test with a comment that is invalid. You can either just catch the parser error and return []
or use error_recovery=True and then handle all the issues.
annotation = tree.String( | ||
repr(str(match.group(1).strip())), | ||
node.start_pos) | ||
annotation.parent = node.parent |
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.
IMO we shoud not actually need to create a string object. We probably have to create a function similar to _evaluate_for_annotation
that can just take a string argument and use that to resolve comment annotations.
I know that it's already used once, so it's not your fault and you don't have to change it. I'll merge anyway if you don't do it in the next few days. If you don't do it I will :)
|
||
cat = Cat(UNKNOWN_NAME4, UNKNOWN_NAME5, UNKNOWN_NAME6) | ||
#? str() | ||
cat.name |
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.
Great set of tests! Thanks!
b9903ed
to
61f2552
Compare
Thanks for the review! :) I've added tests for syntax errors in type comments. These seem to just pass, so it looks like parse errors are already handled somewhere else in jedi. I've also made some minor updates to the docs to say that function annotations are now supported. |
This allows us to use mypy annotations for completion in Python 2. Closes davidhalter#946
61f2552
to
0c3281d
Compare
I merged a little bit before you did the changes and then did some of my changes that I thought were necessary. I will close because the changes have been merged (You force pushed a bit after). I think I have written a bit of a different test than you, but that shouldn't matter. Thanks again for your effort. Good job! :) Happy to merge more of your contributions :) |
Thank you :) |
This allows us to use mypy annotations for completion in Python 2.
This is based on #947, rebased on the latest master. I've also done my best to resolve @davidhalter's feedback on that PR. I've replaced the regexp parsing with a call to
parso.parse
, and moved the tests as suggested.I haven't resolved the comment on
_fix_forward_reference
-- I'm not sure what's wrong with that function that needs fixing.Closes #946.