classification
Title: tkinter documentation suggests "from tkinter import *", contradicting PEP8
Type: Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: ChrisRands, docs@python, ned.deily, serhiy.storchaka
Priority: normal Keywords:

Created on 2018-02-12 12:51 by ChrisRands, last changed 2018-02-12 13:52 by serhiy.storchaka. This issue is now closed.

Messages (6)
msg312045 - (view) Author: (ChrisRands) * Date: 2018-02-12 12:51
Issue arose from this SO post: https://stackoverflow.com/questions/48746351/documentation-is-contradicting-pep8

The tkinter documentation suggests:

from tkinter import *

https://docs.python.org/3/library/tkinter.html

But this obviously contradicts PEP8:
"Wildcard imports (from <module> import *) should be avoided"

https://www.python.org/dev/peps/pep-0008/#imports

Is tkinter a valid exception or is this a documentation bug?

The commit of this line to the documentation is >10 years old (at least Python 2.4 I think): https://github.com/python/cpython/commit/116aa62bf54a39697e25f21d6cf6799f7faa1349#diff-05a258c160de90c51c1948689f788ef7R53
msg312047 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-12 13:09
I think tkinter is a valid exception. It provides the enormous number of names (mostly constants like RIGHT or VERTICAL) which are convenient to use without prefix.

PEP 8 is a style guide for the code of the stdlib. Its suggestions are not mandatory for a user code.
msg312048 - (view) Author: (ChrisRands) * Date: 2018-02-12 13:22
Thanks Serhiy, you might be right (I am not a tkinter user myself).

I also forgot to say that in PEP 328 tkinter is mentioned in this context:
https://www.python.org/dev/peps/pep-0328/#rationale-for-parentheses
msg312049 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-02-12 13:31
PEP 8 also says: "In particular: do not break backwards compatibility just to comply with this PEP!"  This is one of those cases.  There is a ton of code out there that depends on importing tkinter this way for the reasons Serhiy cited.  Thanks for the suggestion but this usage is not going to change.
msg312051 - (view) Author: (ChrisRands) * Date: 2018-02-12 13:39
Ok thanks both for the clarification!
msg312054 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-12 13:52
I want to add that the star import is more convenient when you experiment with Tkinter in REPL. You don't know what names will be needed when import Tkinter.

The interpreter core has a special support of Tkinter. You don't need to run mainloop() for updating GUI in REPL. So this is a supported case.
History
Date User Action Args
2018-02-12 13:52:55serhiy.storchakasetmessages: + msg312054
2018-02-12 13:39:55ChrisRandssetmessages: + msg312051
2018-02-12 13:31:39ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg312049

resolution: not a bug
stage: resolved
2018-02-12 13:22:58ChrisRandssetmessages: + msg312048
2018-02-12 13:09:32serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg312047
2018-02-12 12:51:45ChrisRandscreate