Skip to content

Namespace packages (PEP 420) - #5691

Merged
gvanrossum merged 14 commits into
python:masterfrom
gvanrossum:namespaces
Oct 3, 2018
Merged

Namespace packages (PEP 420)#5691
gvanrossum merged 14 commits into
python:masterfrom
gvanrossum:namespaces

Conversation

@gvanrossum

@gvanrossumgvanrossum commented Sep 29, 2018

Copy link
Copy Markdown
Member

Tentative implementation of PEP 420. Fixes#1645.

Clarification of the implementation:

  • candidate_base_dirs is a list of (dir, verify) tuples, laboriously pre-computed.
  • The old code just looped over this list, looking for dir/<module>, and if found, it would verify that there were __init__.py files in all the right places (except if verify is false); the first success would be the hit;
  • In PEP 420 mode, if the above approach finds no hits, we do something different for those paths that failed due to __init__ verification; essentially we narrow down the list of candidate paths by checking for __init__ files from the top down. Hopefully the last test added clarifies this.

@gvanrossum
gvanrossumforce-pushed the namespaces branch 2 times, most recently from f2c87ff to ecac1b5CompareSeptember 29, 2018 21:07
@gvanrossum
gvanrossum deleted the namespaces branch September 29, 2018 21:08
@gvanrossum
gvanrossum restored the namespaces branch September 29, 2018 21:08
@gvanrossumgvanrossum reopened this Sep 29, 2018
@gvanrossum

Copy link
Copy Markdown
MemberAuthor

(Whoops, accidentally deleted the branch which caused the PR to be closed. I'm not done yet.)

@ilevkivskyiilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is right. At least after reading the PEP and playing a bit, this coincides with the runtime behaviour. I have two more suggestions for tests (apart from nesting normal in namespace and vice versa as you proposed, I just checked, both of these work at runtime).

Comment threadtest-data/unit/check-modules.test
Comment threadtest-data/unit/check-modules.test
@ilevkivskyi

Copy link
Copy Markdown
Member

As I understand this fixes #1645. I would add it to the PR description, so that we will not forget to close the issue :)

@gvanrossum

Copy link
Copy Markdown
MemberAuthor

Alas, tests for nesting one type of package inside the other fail (both ways -- it always prefers the decoy file). It's late so I'll just leave it broken, I'll fix it tomorrow.

@gvanrossum

Copy link
Copy Markdown
MemberAuthor

Hey @carljm, IIRC you expressed interest in namespace packages eons ago. Perhaps you can test this PR with your use case?

@gvanrossum

Copy link
Copy Markdown
MemberAuthor

(Hold on, I have an idea for a refinement of the final part of the algorithm.)

@gvanrossum

Copy link
Copy Markdown
MemberAuthor

@ilevkivskyi I think I'm happy now. Are you?

@ilevkivskyiilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I am happy with this.

Comment threadmypy/modulefinder.py Outdated
# indicates the highest level at which a __init__.py[i] file
# is found; if no __init__ was found it returns 0, if we find
# only foo/bar/__init__.py it returns 1, and if we have
# foo/__init__.py it returns 2 (regardless of what's un

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: 'un' -> 'in'

@gvanrossum
gvanrossum merged commit f59a871 into python:masterOct 3, 2018
@gvanrossum
gvanrossum deleted the namespaces branch October 3, 2018 18:09
TV4Fun pushed a commit to TV4Fun/mypy that referenced this pull request Oct 4, 2018
Tentative implementation of PEP 420. Fixespython#1645.
Clarification of the implementation:
- `candidate_base_dirs` is a list of `(dir, verify)` tuples, laboriously pre-computed.
- The old code just looped over this list, looking for `dir/<module>`, and if found, it would verify that there were `__init__.py` files in all the right places (except if `verify` is false); the first success would be the hit;
- In PEP 420 mode, if the above approach finds no hits, we do something different for those paths that failed due to `__init__` verification; essentially we narrow down the list of candidate paths by checking for `__init__` files from the top down. Hopefully the last test added clarifies this.
gvanrossum added a commit that referenced this pull request Oct 9, 2018
Follow-up for #5691. Should be cherry-picked into the release (#5741). Fixes#5757.
gvanrossum added a commit that referenced this pull request Oct 9, 2018
Follow-up for #5691. Should be cherry-picked into the release (#5741). Fixes#5757.
Sign up for freeto 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.

2 participants

@gvanrossum@ilevkivskyi