I just noticed that relative import like this:
from .foo import myfunc
print myfunc # ok
print foo # ok
imports both foo and myfunc. Is such behaviour documented anywhere? Can I disable it?
-- Update
Basically problem is following.
bar/foo/__init__.py
:
__all__ = ['myfunc']
def myfunc(): pass
bar/__init__.py
:
from .foo import *
# here I expect that there is only myfunc defined
main.py
:
import foo
from bar import * # this import shadows original foo
I can add __all__
to the bar/__init__.py
as well, but that way I have to repeat names in several places.