-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve tkinter 'import *' situation #73632
Comments
Tkinter naming was designed so that 'from tkinter import *' can work, in the sense of not conflicting with built-in and stdlib module names. But there are currently two problems.
...to use Tkinter all you need is a simple import statement: over-promotes 'import *' as the common and therefore normal import (as opposed to a convenience for interactive use). It neglects the alternatives 'import tkinter as tk' or 'from tkinter import Tk, ...', and consequently makes no mention of the relative advantages.
I will work on patches. Since the doc change can apply to all current versions while the code change might be restricted to 3.7, I will keep then separate.
"I would focus on changing habits to discourage "import *" rather than |
There is yet one name that doesn't make sense to import -- wantobjects. It can't be renamed. |
This issue is spun-off from bpo-29162, which was about idlelib.pyshell depending on import * importing sys. 'wantobjects' does not have the same bug potential as stdlib imports. But, Serhiy, if you care about it or otherwise prefer __all__, __all__ = [name for name in globals() if not name.startswith('_') and name not in {'enum', 're', 'sys', 'wantobjects'}] should work if placed near the end of the file, just before 'def _test'. Except for the exclusion set, I presume that 'import *' does essentially the same iteration |
LGTM. |
Instead of: Maybe this would be less fragile: That is, exclude all modules. Admittedly, I had to import types, but there are other ways to do this test without that import. |
This also excludes "constants" implicitly added by importing names from tkinter.constants. I don't know whether this is good or bad. Interesting, but from tkinter import *
import tkinter.ttk and import tkinter.ttk
from tkinter import * have different effects. |
I prefer Eric's approach. It excludes tkinter submodules (like tkinter.ttk). Currently the result of the star import depends on what submodules were imported before. I think it would be better to make it more stable. |
I agree that for python x.y, the names imported by 'import *' should be fixed and *not* depend on other imports. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: