Skip to content

tkinter documentation suggests "from tkinter import *", contradicting PEP8 #77011

Closed

Description

@chris-rands
BPO 32830
Nosy @ned-deily, @serhiy-storchaka, @chris-rands

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:

assignee = None
closed_at = <Date 2018-02-12.13:31:39.867>
created_at = <Date 2018-02-12.12:51:45.084>
labels = ['invalid', 'docs']
title = 'tkinter documentation suggests "from tkinter import *", contradicting PEP8'
updated_at = <Date 2020-12-01.20:59:25.244>
user = 'https://github.com/chris-rands'

bugs.python.org fields:

activity = <Date 2020-12-01.20:59:25.244>
actor = 'busfault'
assignee = 'docs@python'
closed = True
closed_date = <Date 2018-02-12.13:31:39.867>
closer = 'ned.deily'
components = ['Documentation']
creation = <Date 2018-02-12.12:51:45.084>
creator = 'ChrisRands'
dependencies = []
files = []
hgrepos = []
issue_num = 32830
keywords = []
message_count = 7.0
messages = ['312045', '312047', '312048', '312049', '312051', '312054', '382278']
nosy_count = 5.0
nosy_names = ['ned.deily', 'docs@python', 'busfault', 'serhiy.storchaka', 'ChrisRands']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue32830'
versions = []

Activity

  1. chris-rands commented on Feb 12, 2018

    chris-randsmannequin
    MannequinAuthor

    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 PEP-8:
    "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): 116aa62#diff-05a258c160de90c51c1948689f788ef7R53

  2. added
    docs
    on Feb 12, 2018
  3. serhiy-storchaka commented on Feb 12, 2018

    @serhiy-storchaka
    Member

    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.

  4. chris-rands commented on Feb 12, 2018

    chris-randsmannequin
    MannequinAuthor

    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

  5. ned-deily commented on Feb 12, 2018

    @ned-deily
    Member

    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.

  6. chris-rands commented on Feb 12, 2018

    chris-randsmannequin
    MannequinAuthor

    Ok thanks both for the clarification!

  7. serhiy-storchaka commented on Feb 12, 2018

    @serhiy-storchaka
    Member

    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.

  8. busfault commented on Dec 1, 2020

    busfaultmannequin
    Mannequin

    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 PEP-8 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?

  9. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions