This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 'from module import *' and __all__
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryk sun, eryksun, martin.panter, theller
Priority: normal Keywords:

Created on 2016-12-21 08:13 by theller, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg283721 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2016-12-21 08:13
The documentation states that 'from module import *' imports all symbols that are listed in the module's __all__ list.
In Python 3, unlike Python 2, only symbols that do NOT start with an underscore are actually imported.

The following code works in Python 2.7, but raises a NameError
in Python 3.5:
python -c "from ctypes.wintypes import *; print(_ULARGE_INTEGER)"
msg283734 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-21 10:02
Python 3 doesn’t have an __all__ list; it was removed in r85073 (Issue 3612).

I don’t understand why it was removed. Maybe Hirokazu didn’t understand what it does. Since this is a regression, perhaps it should be added back.
msg283748 - (view) Author: Eryk Sun (eryk sun) Date: 2016-12-21 12:04
Python 3 does not skip names in __all__ that start with an underscore. 

wintypes in 2.x uses `from ctypes import *`, so it needs to define __all__. In 3.x it uses `import ctypes`, so it doesn't define __all__, and the private names _COORD, _FILETIME, _LARGE_INTEGER, _POINTL, _RECTL, _SMALL_RECT, and _ULARGE_INTEGER are skipped by a star import. That said, why are these private names (and also "tag" names) defined? And why isn't COORD defined instead of or in addition to _COORD?
msg283763 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2016-12-21 15:55
Thanks Martin and eryk for correcting me and finding the real cause of
the problem.

Am 21.12.2016 um 13:04 schrieb eryk sun:
> ...  the private names _COORD, _FILETIME, _LARGE_INTEGER,
> _POINTL, _RECTL, _SMALL_RECT, and _ULARGE_INTEGER are skipped by a
> star import. That said, why are these private names (and also "tag"
> names) defined? And why isn't COORD defined instead of or in addition
> to _COORD?

These 'private' names and "tag" names were defined for compatibility
with the windows SDK C header files.  I didn't want to apply
the Python 'private' convention to the C names, so they were added to
the __all__ list.
It was an oversight that COORD wasn't defined, I developed a different
solution for the windows SDK names afterwards, but my code (which I'm
porting to Python 3) still uses 'from ctypes.wintypes import *'
and stumbled over the regression just now.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73217
2016-12-21 23:28:32eryksunsetstatus: open -> closed
nosy: + eryksun

resolution: not a bug
stage: resolved
2016-12-21 15:55:22thellersetmessages: + msg283763
2016-12-21 12:04:39eryk sunsetnosy: + eryk sun
messages: + msg283748
2016-12-21 10:02:57martin.pantersetversions: - Python 3.3, Python 3.4
nosy: + martin.panter

messages: + msg283734

components: + Library (Lib), - Interpreter Core
2016-12-21 08:13:10thellercreate