[issue23447] Relative imports with __all__ attribute
New submission from Antonio Cota: That's the situation: a/ __init__.py first.py second.py #init.py __all__ = ['second', 'first'] print('i\'m starting the directory') #first.py print('hi, i\'m the first') from . import * #second.py print('hi, i\'m the second') >From the interactive prompt: >>> import a.first i'm starting the directory hi, i'm the first hi, i'm the second Traceback (most recent call last): File "", line 1, in File "/home/antox/Scrivania/a/first.py", line 2, in from . import * AttributeError: module 'a' has no attribute 'first' It's pretty weird. -- messages: 235761 nosy: antox priority: normal severity: normal status: open title: Relative imports with __all__ attribute type: behavior versions: Python 3.5 ___ Python tracker <http://bugs.python.org/issue23447> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23447] Relative imports with __all__ attribute
Changes by Antonio Cota : -- versions: +Python 3.4 ___ Python tracker <http://bugs.python.org/issue23447> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23447] Relative imports with __all__ attribute
Antonio Cota added the comment: I tried the following on python 3.5.0a1: #init.py __all__ = ['second', 'first'] print('i\'m starting the directory') #first.py print('hi, i\'m the first') from . import second #second.py print('hi, i\'m the second') from . import first >>> import a.first i'm starting the directory hi, i'm the first hi, i'm the second it just worked out perfectly, no errors. But the case I show before still continues to get the AttributeError error. You told me that basically it doesn't work because it is a circular import, but isn't python already able to manage circular import? What I expected when running the "from . import *" statament was Python looking up in the __all__ attribute and import everything within it. When it had to import 'first' I expected Python to check in the sys.modules to see if it was already imported so, in this case, it could see that first.py was already imported and no error was raised. -- ___ Python tracker <http://bugs.python.org/issue23447> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23447] Relative imports with __all__ attribute
Changes by Antonio Cota : -- versions: -Python 3.4 ___ Python tracker <http://bugs.python.org/issue23447> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com