Conversation
The docs describe prefix as "a string to output on the front of every module name on output". That is accurate for iter_modules(), but it leaves out the part that catches people in walk_packages(): the same string goes into the name each package is imported under while the walk descends, so the descent only reaches a package when prefix + name resolves to the very package that was found on path. When it resolves to something else, that other package is walked instead. When importing it raises ImportError, the submodules are absent and nothing in the results says so. Walking ctypes.__path__ with no prefix on the current main lists six names and quietly loses the three modules under ctypes.macholib; with ctypes.__name__ + '.' it lists all nine. Passing onerror does not make up for it, which is easy to assume from the old wording: it reports macholib, and the output is still the same six names. Only the wording changes, in the rst and in the docstring that repeats it. The implementation problem Nick Coghlan described on the same report, that the descent goes through a name-based __import__ instead of loading the package from the file it has already found, is left alone here; pull request python#11956 is already open for it.
Documentation build overview
|
Author
|
Closing this myself. @picnixz pointed out on #158152 that I have been opening too many at once and that old issues nobody has revived are the wrong ones to pick up unasked — this is one of those, so it should not be sitting in the queue. The branch stays on my fork if the issue ever comes back to life. |
Author
|
Reopened. Closing this was my own overreaction to being told I had too many open, not something anyone asked for. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #77391, the documentation half of it.
@ncoghlan split the issue in two back in 2018:
The docs describe prefix as something prepended to the names on output, which reads as cosmetic. It is also the name each package gets imported under during the descent, and that has consequences a reader has no way to guess. Three of them, all on a tree where
realpkg/sub/leaf.pyexists andother/sub/wrongleaf.pyis a decoy:No prefix, so
subis imported by bare name, that fails, andleafis silently missing — nothing in the result says a subtree was skipped.With the right prefix the descent works.
The path pointed at
realpkg, but the prefix made it importother.sub, so what came back is the content of a package that was never on the given path.The wording now says that, and says the thing a caller actually needs: pass a package's
__path__together with its__name__and a trailing dot. Same text in the docstring, since that is where most people read it.Doc and docstring only, no behaviour change. The functional half @ncoghlan described is untouched.