Re: Import semantics?
Dan Stromberg wrote: Did the import semantics change in cpython 3.3a4? I used to be able to import treap.py even though I had a treap directory in my cwd. With 3.3a4, I have to rename the treap directory to see treap.py. Check out PEP 420 -- Implicit Namespace Packages [http://www.python.org/dev/peps/pep-0420/] ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Import semantics?
On Fri, Jun 8, 2012 at 3:16 PM, Ethan Furman et...@stoneleaf.us wrote: Dan Stromberg wrote: Did the import semantics change in cpython 3.3a4? I used to be able to import treap.py even though I had a treap directory in my cwd. With 3.3a4, I have to rename the treap directory to see treap.py. Check out PEP 420 -- Implicit Namespace Packages [ http://www.python.org/dev/peps/pep-0420/] Am I misinterpreting this? It seems like according to the PEP, I should have still been able to import treap.py despite having a treap/. But I couldn't; I had to rename treap/ to treap-dir/ first. During import processing, the import machinery will continue to iterate over each directory in the parent path as it does in Python 3.2. While looking for a module or package named foo, for each directory in the parent path: - If directory/foo/__init__.py is found, a regular package is imported and returned. - If not, but directory/foo.{py,pyc,so,pyd} is found, a module is imported and returned. The exact list of extension varies by platform and whether the -O flag is specified. The list here is representative. - If not, but directory/foo is found and is a directory, it is recorded and the scan continues with the next directory in the parent path. - Otherwise the scan continues with the next directory in the parent path. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Import semantics?
On Fri, Jun 8, 2012 at 4:24 PM, Dan Stromberg drsali...@gmail.com wrote: Am I misinterpreting this? It seems like according to the PEP, I should have still been able to import treap.py despite having a treap/. But I couldn't; I had to rename treap/ to treap-dir/ first. That's how I understand it. The existence of a module or regular package 'foo' anywhere in the path should trump the creation of a 'foo' namespace package, even if the namespace package would be earlier in the path. Ar you sure you don't have an __init__.py in your treap directory? -- http://mail.python.org/mailman/listinfo/python-list
Re: Import semantics?
On Fri, Jun 8, 2012 at 6:24 PM, Dan Stromberg drsali...@gmail.com wrote: Am I misinterpreting this? It seems like according to the PEP, I should have still been able to import treap.py despite having a treap/. But I couldn't; I had to rename treap/ to treap-dir/ first. Only if treap/ and treap.py were in the same directory. Otherwise it looks like whichever comes first in the search path is imported first. -- Devin -- http://mail.python.org/mailman/listinfo/python-list
Re: Import semantics?
On Fri, Jun 8, 2012 at 3:48 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Fri, Jun 8, 2012 at 4:24 PM, Dan Stromberg drsali...@gmail.com wrote: Am I misinterpreting this? It seems like according to the PEP, I should have still been able to import treap.py despite having a treap/. But I couldn't; I had to rename treap/ to treap-dir/ first. That's how I understand it. The existence of a module or regular package 'foo' anywhere in the path should trump the creation of a 'foo' namespace package, even if the namespace package would be earlier in the path. Ar you sure you don't have an __init__.py in your treap directory? The issue replicated in a minimal way (it's in the ticket too): dstromberg@zareason-limbo6000a /tmp/tt $ mv treap treap-dir dstromberg@zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python -c 'import sys; print(sys.path); import treap; t = treap.treap()' ['', '/usr/local/cpython-3.3/lib/python33.zip', '/usr/local/cpython-3.3/lib/python3.3', '/usr/local/cpython-3.3/lib/python3.3/plat-linux', '/usr/local/cpython-3.3/lib/python3.3/lib-dynload', '/usr/local/cpython-3.3/lib/python3.3/site-packages'] dstromberg@zareason-limbo6000a /tmp/tt $ mv treap-dir/ treap dstromberg@zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python -c 'import sys; print(sys.path); import treap; t = treap.treap()' ['', '/usr/local/cpython-3.3/lib/python33.zip', '/usr/local/cpython-3.3/lib/python3.3', '/usr/local/cpython-3.3/lib/python3.3/plat-linux', '/usr/local/cpython-3.3/lib/python3.3/lib-dynload', '/usr/local/cpython-3.3/lib/python3.3/site-packages'] Traceback (most recent call last): File string, line 1, in module AttributeError: 'module' object has no attribute 'treap' dstromberg@zareason-limbo6000a /tmp/tt $ ls -l treap/__init__.py ls: cannot access treap/__init__.py: No such file or directory dstromberg@zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python Python 3.3.0a4 (default, Jun 8 2012, 14:14:41) [GCC 4.6.1] on linux Type help, copyright, credits or license for more information. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Import semantics?
And a link to the ticket: http://bugs.python.org/issue15039 -- http://mail.python.org/mailman/listinfo/python-list