Proposal for new, intrinsic module object attribute: __path__

Ken Manheimer (ken.manheimer@NIST.GOV)
Thu, 02 Feb 1995 13:46:20 -0500 (EST)

I would like to propose that:

- the path from which a module is imported, if any, be explicitly
and publicly registered in the module itself, eg as
'amodule.__path__',

- 'reload(amodule)' use that path, rather than re-searching the load
path for the module.

I had assumed until just recently that 'reload(amodule)' actually used
a hidden attribute representing the path from which the module was
loaded. But then i noticed that a chdir made reload of a module found
via the '.' entry fail. (Even worse, if the module happens to exist
elsewhere on the path, the entirely different module would wind up
being found.)

It seems to me that a module object is more closely coupled with the
specific file contents, as opposed to the module name. Ie, when you
'reload' a module, you mean to obtaining the changed contents, as
opposed to reassigning the name according to changes of the load-path
and working directory, etc.

This will become more of an issue if and when my (pending) packages
implementation is incorporated in python.

I'm not sure what else to say to substantiate the merits of this
proposal. Is the current setup - re-path-search on reload -
deliberate, or just an artifact of convenient implementation? The
only kinds of advantages that i can see with the current
implementation have to do with switching a module from one file to
another, and there are (1) probably other ways to provide that
operation, and (2) there will probably be less need for such an
operation when packages are implemented... I guess that's kinda vague
- i would be interested to hear, and address if i can, the specific
reasons...

?

Ken
ken.manheimer@nist.gov, 301 975-3539