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

Support mypy annotations using Python 2 comment syntax #1002

Closed
wants to merge 1 commit into from

Conversation

Wilfred
Copy link

@Wilfred Wilfred commented Nov 24, 2017

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.

@davidhalter
Copy link
Owner

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 :)

@Wilfred Wilfred force-pushed the function_comment branch 3 times, most recently from ec7886e to b9903ed Compare March 13, 2018 17:56
@Wilfred
Copy link
Author

Wilfred commented Mar 13, 2018

Rebased. Almost all of the tests are passing, except Python 2.7 on JEDI_TEST_ENVIRONMENT=35 and 36:

ValueError: malformed node or string: b"u'str'"

It's not clear to me what's going on here.

Copy link
Owner

@davidhalter davidhalter left a 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]
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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!

@Wilfred
Copy link
Author

Wilfred commented Mar 14, 2018

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
@davidhalter
Copy link
Owner

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 :)

@Wilfred
Copy link
Author

Wilfred commented Mar 15, 2018

Thank you :)

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

Successfully merging this pull request may close these issues.

Support for python2 type comments
2 participants