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
pydoc info for a package doesn't list all package contents #44328
Comments
When using pydoc to query a package, a "PACKAGE CONTENTS" list is provided to show the modules and packages that are in that package. That list will be incomplete if we are querying a package that has been split across multiple directories. Suppose you have the following: /first/path/foo/init.py and sys.path includes /first/path/ and /second/path/. If both of the foo/init.py files are empty, then "import foo" will only allow you to import modules from one of those two foo/ directories (whichever is found first in sys.path). However, if we add the following to both foo/init.py files, then we can import foo.one and foo.two because "foo" is considered to be a single package split across two directories: from pkgutil import extend_path
__path__ = extend_path(__path__, __name__) Please see http://www.python.org/doc/2.4.2/lib/module-pkgutil.html for some related information. On line 1052 of pydoc.py, we have the following: for file in os.listdir(object.__path__[0]): and in that loop we only read the contents of the FIRST directory in the package's __path__. That should be updated to read the contents of ALL directories in the package's __path__. The following change will do that: % diff -w pydoc.py pydoc.py.orig
I've attached that updated pydoc.py file to this submission. Please consider that as a replacement for the existing pydoc.py module that's currently being distributed. |
Surely this is a bug? |
I’ve just tested that the behavior is now correct. I reproduced the tree structure, set PYTHONPATH, ran “pydoc foo” to get only “one” listed, added the pkgutil call in first/path/foo/init.py, re-ran “pydoc foo”, got “one” and “two” listed. I can also import both submodules. The pydoc code now uses pkgutil.iter_modules. Someone must have fixed that before 2.6, closing. Thanks for the report nonetheless! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: