[issue32830] tkinter documentation suggests "from tkinter import *", contradicting PEP8

New submission from ChrisRands <chrisrands0@gmail.com>: Issue arose from this SO post: https://stackoverflow.com/questions/48746351/documentation-is-contradicting-... 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/116aa62bf54a39697e25f21d6cf6799f7fa... ---------- assignee: docs@python components: Documentation messages: 312045 nosy: ChrisRands, docs@python priority: normal severity: normal status: open title: tkinter documentation suggests "from tkinter import *", contradicting PEP8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32830> _______________________________________

Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment: 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. ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32830> _______________________________________

ChrisRands <chrisrands0@gmail.com> added the comment: 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 ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32830> _______________________________________

Ned Deily <nad@python.org> added the comment: 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. ---------- nosy: +ned.deily resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32830> _______________________________________

ChrisRands <chrisrands0@gmail.com> added the comment: Ok thanks both for the clarification! ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32830> _______________________________________

Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32830> _______________________________________

Tom Middleton <busfault@gmail.com> added the comment: While I agree that it shouldn't be imposed on changing previous code, changing the documentation isn't changing the previous code it is encouraging future code. I think that the documentation should have a caveat. I'm seeing a lot of new code using tkinter with glob import which is obviously from the documentation as it suggests doing so. I think that the glob import practice should be overall discouraged. I think adding a disclaimer in the documentation at the reference to `from tkinter import *` would be sufficient. A reference to PEP8 would be good. I'd imagine that most people look up docs and are not as familiar with PEP. Why can't something like that be added to the documentation? ---------- nosy: +busfault _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32830> _______________________________________
participants (4)
-
ChrisRands
-
Ned Deily
-
Serhiy Storchaka
-
Tom Middleton