[issue23447] Relative imports with __all__ attribute

2015-02-12 Thread Steven Barker

Steven Barker added the comment:

This issue is a special case of the problem discussed in issue 992389, that 
modules within packages are not added to the package dictionary until they are 
fully loaded, which breaks circular imports in the form from package import 
module.

The consensus on that issue is that it doesn't need to be fixed completely, 
given the partial fix from issue 17636. I think the current issue is a corner 
case that was not covered by the fix, but which probably should be fixed as 
well, for consistency. The fix so far has made imports that name the module 
work, even though the module objects are still not placed into the package's 
namespace yet (this is why Antonio's last example works in the newly released 
3.5a1, though not in previous versions). Wildcard imports however still fail.

Can the fix be expanded to cover wildcard imports as well? I know, we're 
heaping up two kinds of usually-bad code (wildcard imports and circular 
imports) on top of one another, but still, the failure is very unexpected to 
anyone who's not read the bug reports.

I don't know my way around the import system at all yet, so I'm not going to be 
capable of writing up a patch immediately, but if there's any interest at all, 
and nobody more knowledgeable gets to it first I might see what I can learn and 
try to put together something.

Here's a more concise example of the issue:


package/__init__.py:

__all__ = [module]


package/module.py:

from . import module # this works in 3.5a1, thanks to the fix from issue 
17636
from . import *  # this still fails

--
nosy: +Steven.Barker

___
Python tracker rep...@bugs.python.org
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

2015-02-12 Thread Brett Cannon

Brett Cannon added the comment:

If you put a print call after your `from . import *` call you will notice it 
never gets executed. Basically import is still in the middle of finishing 
imports when that import * is reached, including setting the module attributes 
on the package. Basically you have a circular import.

--
nosy: +brett.cannon
resolution:  - not a bug
status: open - closed

___
Python tracker rep...@bugs.python.org
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

2015-02-12 Thread Antonio Cota

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 rep...@bugs.python.org
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

2015-02-12 Thread Antonio Cota

Changes by Antonio Cota antocot...@gmail.com:


--
versions:  -Python 3.4

___
Python tracker rep...@bugs.python.org
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

2015-02-11 Thread Antonio Cota

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 stdin, line 1, in module
  File /home/antox/Scrivania/a/first.py, line 2, in module
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 rep...@bugs.python.org
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

2015-02-11 Thread Antonio Cota

Changes by Antonio Cota antocot...@gmail.com:


--
versions: +Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23447
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com