Issue 29031: 'from module import *' and all (original) (raw)
Issue29031
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) * ![]() |
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) * ![]() |
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) * ![]() |
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:40 | admin | set | github: 73217 |
2016-12-21 23:28:32 | eryksun | set | status: open -> closednosy: + eryksunresolution: not a bugstage: resolved |
2016-12-21 15:55:22 | theller | set | messages: + |
2016-12-21 12:04:39 | eryk sun | set | nosy: + eryk sunmessages: + |
2016-12-21 10:02:57 | martin.panter | set | versions: - Python 3.3, Python 3.4nosy: + martin.pantermessages: + components: + Library (Lib), - Interpreter Core |
2016-12-21 08:13:10 | theller | create |