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

Relative imports should work even if they are not within the project #1684

Merged
merged 6 commits into from Dec 22, 2020

Conversation

davidhalter
Copy link
Owner

See comments in code.

This is another potential solution for #1655 (and an answer to #1662 as well).

@PeterJCLaw I was a bit confused in the beginning why this was happening, but I understand it better now. This was an issue on all platforms. We could of course still use #1662 or at least parts of it, but I guess this is the more important part.

Copy link
Collaborator

@PeterJCLaw PeterJCLaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this improves some cases, though to be honest I'm not sure I completely follow how this code works (I've only had a fairly quick look).
I'll have another play with #1655 soon (which I think we're going to want the str/Path fixing from anyway) and have another look at this afterwards.

test/test_api/test_usages.py Show resolved Hide resolved
test/test_inference/test_imports.py Outdated Show resolved Hide resolved
jedi/inference/imports.py Outdated Show resolved Hide resolved
test/test_api/test_usages.py Show resolved Hide resolved
if not self.import_path or not self._infer_possible:
if not self.import_path:
if self._fixed_sys_path:
# This is a bit of a special case, that maybe should be
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description here of why the code is needed/is special feels out of step with the test which validates the behaviour. Perhaps I'm missing something, but is there more to this code than just the niche case described here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's simply that.

It's just a special case, because it breaks the basic idea of something being on the sys path. Do you need further explanations?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry. I think if this code were here just for the special case, which this comment suggests is to do with the same name appearing at several levels in the hierarchy, then on reading this comment alone I would assume that it would only be activated by that special case and that the test to validate it would exercise that case. However the test doesn't actually seem to hit that case (the directory names it chooses differ at each level), yet this code path is taken.

Clearly the test that is present is a useful test and this codepath is useful in making it work, so perhaps this comment could be tweaked to clarify that this codepath is here for all cases of namespace packages, rather than just for the case of matching names?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my comment just wasn't good enough. Because having the same names is just one case. Will try to improve :)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a bit to the comment.

Once I merge this, I will probably make a release.

Also sorry about the delay, but had to await my firstborn :)

davidhalter and others added 3 commits October 21, 2020 22:32
Co-authored-by: Peter Law <PeterJCLaw@gmail.com>
Co-authored-by: Peter Law <PeterJCLaw@gmail.com>
@codecov-io
Copy link

codecov-io commented Oct 24, 2020

Codecov Report

Merging #1684 (bc4f6ed) into master (42a759a) will increase coverage by 0.00%.
The diff coverage is 87.50%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1684   +/-   ##
=======================================
  Coverage   94.52%   94.53%           
=======================================
  Files          79       79           
  Lines       11762    11780   +18     
=======================================
+ Hits        11118    11136   +18     
  Misses        644      644           
Impacted Files Coverage Δ
jedi/inference/imports.py 98.62% <87.50%> (-0.32%) ⬇️
jedi/inference/value/module.py 99.27% <0.00%> (+0.06%) ⬆️
jedi/inference/names.py 96.42% <0.00%> (+0.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42a759a...bc4f6ed. Read the comment docs.

@davidhalter davidhalter merged commit b89f944 into master Dec 22, 2020
@davidhalter davidhalter deleted the relative-import branch December 22, 2020 22:18
@davidhalter
Copy link
Owner Author

@PeterJCLaw I merged, because I think this was at least good enough. Please let me know if you think it's still not good enough and I will fix it for the next release.

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.

None yet

3 participants