classification
Title: set __path__ = [] for frozen packages
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: barry, brett.cannon, python-dev
Priority: normal Keywords:

Created on 2013-05-25 23:21 by brett.cannon, last changed 2013-06-01 03:23 by brett.cannon. This issue is now closed.

Messages (2)
msg190034 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-05-25 23:21
If you import the frozen __phello__ package, you will notice that __phello__.__path__ == ['__phello__']. While that seems innocuous, that could potentially lead to incorrect results if there just so happens to be a directory named __phello__ which contains a file that isn't a frozen submodule (i.e. FrozenImporter can't find the submodule but PathFinder can find a file that happens to match the module's name).

So for that reason I want to simply set __path__ = [] for frozen packages. The language reference for import states setting __path__ to anything makes a module a package and that it just needs to be an iterable that only returns strings (http://docs.python.org/3.4/reference/import.html#packages), so an empty list works. Plus __package__ contains the same information so there is no lost data by doing this.

Can anyone think of a good reason not to do this? I can't see why someone would be relying upon this for any reason since the existence of __path__ itself is enough to determine something is a package.
msg190436 - (view) Author: Roundup Robot (python-dev) Date: 2013-06-01 03:18
New changeset 82db02a2e023 by Brett Cannon in branch 'default':
Issue #18065: For frozen packages set __path__ to [].
http://hg.python.org/cpython/rev/82db02a2e023
History
Date User Action Args
2013-06-01 03:23:06brett.cannonsetstatus: open -> closed
resolution: fixed
stage: test needed -> resolved
2013-06-01 03:18:48python-devsetnosy: + python-dev
messages: + msg190436
2013-05-28 14:37:29barrysetnosy: + barry
2013-05-25 23:21:02brett.cannoncreate