While writing a Python package I encountered some strange behavior. This is my directory layout:
my_package/
__init.py__
client.py
events.py
utils.py
In __init__.py
there are some from ...
imports that import various names:
__all__ = ['Client', 'get_websocket_url', 'format_cookies']
from .client import ChatSession as Client
from .utils import get_websocket_url, format_cookies
When I import my_package
and run dir(my_package)
, it seems that client.py
, events.py
, and utils.py
are all included as attributes:
['Client', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'client', 'events', 'format_cookies', 'get_websocket_url', 'utils']
What is the reason that this happens? I was able to remove those attributes by del
eting them in __init__.py
but that doesn't look very good to linters. The only other file that imports anything is client.py
:
from .events import Event
from .utils import get_websocket_url
...
But this doesn't import any module as a whole, so this is puzzling me. Any thoughts?