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

Provide first component of dotted path to namespace searches #1575

Merged
merged 8 commits into from
May 30, 2022

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented May 29, 2022

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

Type of Changes

Type
βœ“ πŸ› Bug fix

Related Issue

Fixes (unreleased) crash reported here. My current theory is that this function should only be using the top-level package name as the search path.. EDIT: no, I'm back to thinking it's better to just catch the KeyError and return False.

@coveralls
Copy link

coveralls commented May 29, 2022

Pull Request Test Coverage Report for Build 2409772032

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.002%) to 91.915%

Totals Coverage Status
Change from base Build 2386640843: -0.002%
Covered Lines: 9231
Relevant Lines: 10043

πŸ’› - Coveralls

@jacobtylerwalls jacobtylerwalls marked this pull request as draft May 29, 2022 14:26
@jacobtylerwalls
Copy link
Member Author

The alternative I'm looking at is just catching KeyError -- this might be a limitation of importlib, and I want to see first if there are any CPython issue discussions about it.

@Pierre-Sassoulas Pierre-Sassoulas self-requested a review May 29, 2022 14:36
@jacobtylerwalls
Copy link
Member Author

jacobtylerwalls commented May 29, 2022

Will await feedback on python/cpython#93334

@jacobtylerwalls jacobtylerwalls changed the title Use first component of dotted path only in namespace searches Catch KeyError during namespace package searches May 29, 2022
@jacobtylerwalls jacobtylerwalls marked this pull request as ready for review May 29, 2022 18:55
@jacobtylerwalls jacobtylerwalls added this to the 2.12.0 milestone May 29, 2022
@DanielNoord
Copy link
Collaborator

We don't want to wait for response from cpython?

@Pierre-Sassoulas
Copy link
Member

Seeing the label on the CPython issue we'll need a "temporary" patch for 3.7, 3.8, 3.9.

@DanielNoord
Copy link
Collaborator

Don't we want to be sure that this is a bug? Otherwise the TODO doesn't make a lot of sense?

@jacobtylerwalls
Copy link
Member Author

@DanielNoord yeah, I wasn't very confident of the correct behavior here but reading python/cpython#89754 suggests that explicitly giving the topmost parent package is probably correct. I just didn't want to change it in case it could miss someone's namespace package, but I realized this is only relevant if it's not on sys.path already, and that's on the user to take care of.

@jacobtylerwalls jacobtylerwalls changed the title Catch KeyError during namespace package searches Provide first component of dotted path to namespace searches May 30, 2022
@@ -0,0 +1,2 @@
This submodule should have the same name as a directory in the root of the project that
Copy link
Collaborator

Choose a reason for hiding this comment

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

At some point we should really move these files to a tests/data directory instead of this one...

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas May 30, 2022

Choose a reason for hiding this comment

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

There is definitely some cleanup to do in the tests directory, there is also the issue of legacy functional tests. https:/PyCQA/pylint/blob/main/tests/test_func.py#L117 nvm it's in pylint

# Only relevant if package not already on sys.path
# See https:/python/cpython/issues/89754 for reasoning
# Otherwise can raise bare KeyError: https:/python/cpython/issues/93334
found_spec = _find_spec_from_path(working_modname, components[0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jacobtylerwalls Just thinking about this again. We cached this function because of importlib being slow in #1536 (comment). (My very first review comment there).

What if we try to get the spec of:
a.b.c.d.e.f.g and then a.b.c.d.e.f.h? We don't benefit from any of the caching right?

Copy link
Member Author

Choose a reason for hiding this comment

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

True, but I don't know if we ever confirmed that this use of importlib was slow. It's slow if importlib is actually importing the parent modules (why we did the #1409 to revert) but the whole point of this approach was to not do that, so I'm not sure it's an issue.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

I don't see anything wrong with this but it's very easy to break something when touching namespace / imports, and if we break something we're going to get an issue with 10+ thumbs up an hour, so I'm still a little nervous πŸ˜„

@jacobtylerwalls
Copy link
Member Author

I'm still a little nervous

I hear that! We could do another beta for pylint 2.15.

@Pierre-Sassoulas
Copy link
Member

I hear that! We could do another beta for pylint 2.15.

How do you feel about astroid 2.12 in pylint 2.14 ? Possible, desirable ? Should we delay this particular MR until astroid 2.13 ? Or were you thinking of using 2.12 only in pylint 2.15 ?

@jacobtylerwalls
Copy link
Member Author

jacobtylerwalls commented May 30, 2022

How do you feel about astroid 2.12 in pylint 2.14 ? Possible, desirable ? Should we delay this particular MR until astroid 2.13 ? Or were you thinking of using 2.12 only in pylint 2.15 ?

I guess I'd hope to just tidy up the changelog for 2.14 and no more functional changes, since we already had a healthy beta period.

Or were you thinking of using 2.12 only in pylint 2.15 ?

⬆️ πŸ’―

@Pierre-Sassoulas Pierre-Sassoulas merged commit c4cc193 into pylint-dev:main May 30, 2022
@jacobtylerwalls
Copy link
Member Author

Rats,I missed it by a few seconds. I found more KeyErrors. I'm going to revert to the other approach.

@Pierre-Sassoulas
Copy link
Member

Sorry about that !

@jacobtylerwalls
Copy link
Member Author

no worries, it's my fault for not immediately marking as draft!

jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request May 30, 2022
@jacobtylerwalls jacobtylerwalls deleted the django-crash branch May 30, 2022 17:51
jacobtylerwalls added a commit that referenced this pull request May 30, 2022
Provide `ModuleSpec.submodule_search_locations` to the `path` argument of `PathFinder.find_spec()`
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.

4 participants