This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pydoc info for a package doesn't list all package contents
Type: behavior Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, ngrover
Priority: normal Keywords: patch

Created on 2006-12-11 20:40 by ngrover, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pydoc.py ngrover, 2006-12-11 20:40
Messages (3)
msg30787 - (view) Author: Nishkar Grover (ngrover) Date: 2006-12-11 20:40
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
/first/path/foo/one.py
/second/path/foo/__init__.py
/second/path/foo/two.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
1052,1054c1052,1053
<             for objectDir in object.__path__:
<                 for file in os.listdir(objectDir):
<                     path = os.path.join(objectDir, file)
---
>             for file in os.listdir(object.__path__[0]):
>                 path = os.path.join(object.__path__[0], file)

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.
msg109838 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-10 09:56
Surely this is a bug?
msg127831 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-02-04 00:03
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!
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44328
2011-02-04 00:03:51eric.araujosetstatus: open -> closed
versions: - Python 3.1, Python 2.7, Python 3.2
nosy: + eric.araujo, - BreamoreBoy
messages: + msg127831

resolution: out of date
stage: test needed -> resolved
2010-07-10 09:56:53BreamoreBoysetversions: + Python 3.2
nosy: + BreamoreBoy

messages: + msg109838

type: enhancement -> behavior
2009-03-30 18:00:22ajaksu2setkeywords: + patch
stage: test needed
type: enhancement
versions: + Python 3.1, Python 2.7, - Python 2.4
2006-12-11 20:40:12ngrovercreate