Message148576
On Nov 29, 2011, at 12:50 PM, Éric Araujo wrote:
>Before you put more work into this, it would be nice to get confirmation from
>one import expert that the bug is valid: I know the import system only
>superficially, and I’m not sure that package/__init__.pyc / .pyo is supported
>by import (if not, then pkgutil should also not support it).
It's an interesting question. Under Python 2, I'd say yes, it should support
source-less imports, just as Python does. Under Python 3, with PEP 3147, I'm
not so sure:
$ cat > foo.py
print('hello world')
$ cat > bar.py
import foo
$ ls
bar.py foo.py
$ python3 bar.py
hello world
$ ls
bar.py foo.py __pycache__/
$ ls __pycache__/
foo.cpython-32.pyc
$ rm -f foo.py
$ python3 bar.py
Traceback (most recent call last):
File "bar.py", line 1, in <module>
import foo
ImportError: No module named foo
Then:
$ mv __pycache__/foo.cpython-32.pyc foo.pyc
$ ls
bar.py foo.pyc __pycache__/
$ python3 bar.py
hello world
So Python 3 source-less imports are still supported, but only when legacy
.pyc/.pyo locations are explicitly used.
My inclination is then -0 on extend_path() supporting .pyc/.pyo but only
*outside* the context of PEP 3147. I.e. do not use imp.cache_from_source(). |
|
Date |
User |
Action |
Args |
2011-11-29 15:09:16 | barry | set | recipients:
+ barry, pje, ncoghlan, eric.araujo, Alexandre.Badez, eric.snow |
2011-11-29 15:09:15 | barry | link | issue11374 messages |
2011-11-29 15:09:15 | barry | create | |
|