New submission from Quentin Agren <[email protected]>:
I'm running Python 3.6 on Ubuntu 16.04
I don't know if this should qualify as a bug, but I noticed the following
behavior difference in the (contrived?) scenario of directly importing
'__init__' from a package:
## Setup ##
mkdir app
echo 'print(f"Executing app/__init__.py as {__name__}")' > app/__init__.py
## Native: executes __init__ *once* ##
python -c 'from app import __init__'
# Output:
# Executing app/__init__.py as app
## Importlib: executes __init__ *twice* ##
python -c "import importlib; importlib.import_module('.__init__', 'app')"
# Output:
# Executing app/__init__.py as app
# Executing app/__init__.py as app.__init__
Note in addition that absolute import (either with importlib or native)
executes '__init__' twice.
----------
components: Library (Lib)
messages: 328512
nosy: qagren
priority: normal
severity: normal
status: open
title: 'from app import __init__' behaves differently with native import and
importlib
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35073>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com