[issue27455] Fix tkinter examples to be PEP8 compliant

New submission from John Hagen: Patch fixes tkinter examples to be PEP8 compliant. ---------- assignee: docs@python components: Documentation files: 0001-Fix-tkinter-docs-PEP8.patch keywords: patch messages: 269820 nosy: John Hagen, docs@python priority: normal severity: normal status: open title: Fix tkinter examples to be PEP8 compliant versions: Python 3.5, Python 3.6 Added file: http://bugs.python.org/file43627/0001-Fix-tkinter-docs-PEP8.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

SilentGhost added the comment: This patch is going to be rejected, camelCase is standard convention in tkinter and logging modules and that's why it is used in documentation as well. ---------- nosy: +SilentGhost _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Berker Peksag added the comment: Thanks for the patch. If you want to improve the examples in tkinter documentation, I'd suggest to update Class.__init__(self, ...) to super().__init__(...). There is no old-style classes in Python 3 anymore so those examples could be updated safely. Also, please read https://docs.python.org/devguide/patch.html. Sending a patch from a Git checkout will only make the review process harder (and I will personally ignore them in the future). ---------- nosy: +berker.peksag, terry.reedy stage: -> patch review type: -> enhancement _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Changes by John Hagen <johnthagen@gmail.com>: Removed file: http://bugs.python.org/file43627/0001-Fix-tkinter-docs-PEP8.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

John Hagen added the comment: @Berker, sorry for the incorrect diff format, still new to CPython (and Mercurial) workflow. I've attached the diff in a new format. @SilentGhost I see what you mean that camelCase is used often in tkinter (though many of the examples use lower_camel_case, so it seems like at least it's not consistent currently). The minor issue I was trying to fix with this patch is that I was showing a programmer completely new to Python the tkinter example and when he pasted it into PyCharm it had some PEP8 warnings, so I was hoping to improve that experience slightly for others in the future. Some of the changes were newlines for PEP8, would those be accepted? I'm not strongly inclined either way, so if the core team thinks it should not be changed, I'm happy with that. ---------- Added file: http://bugs.python.org/file43628/0001-Fix-tkinter-docs-PEP8.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Terry J. Reedy added the comment: Except for replacing '' with ""*, I am strongly for this patch. To me, caMelcaSe is ugLy, and should not be encouraged. I disagree that camelCase is standard convention, at least not currently. Tkinter itself does not use it. It does not even use TitleCase much. As near as I could find, neither http://effbot.org/tkinterbook/tkinter-index.htm nor http://www.tkdocs.com/tutorial/index.html introduce camelCase identifiers. For instance, http://effbot.org/tkinterbook/tkinter-hello-again.htm, instead of hiThere and sayHi, has self.hi_there = Button(frame, text="Hello", command=self.say_hi) def say_hi(self): * PEP 8 says "In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this." My personal convention is 'word', which occurs a lot in tkinter code, and 'multi-word phrase or sentence", which is much rarer. Why the change in the patch. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Changes by Terry J. Reedy <tjreedy@udel.edu>: ---------- components: +Tkinter _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

John Hagen added the comment: @Terry The reason for changing the quotes was for consistency, since everywhere else on that page used double quotes. That being said, I don't have a strong preference and will happily revert it if that is the consensus. I'm +0 on the change. I personally use single quotes everywhere and use flake8-quotes to help with this. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Changes by John Hagen <johnthagen@gmail.com>: Removed file: http://bugs.python.org/file43628/0001-Fix-tkinter-docs-PEP8.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

John Hagen added the comment: @Terry I've removed the two string quotes changes in the latest patch. @Berker I spent a small amount of time trying out your proposed super() changes, but could not get them to work on 3.5.1. "C:\Users\John Hagen\AppData\Local\Programs\Python\Python35\python.exe" "C:/Users/John Hagen/PycharmProjects/test/test.py" Traceback (most recent call last): File "C:/Users/John Hagen/PycharmProjects/test/test.py", line 25, in <module> app = Application(master=root) File "C:/Users/John Hagen/PycharmProjects/test/test.py", line 6, in __init__ super().__init__(self, master) File "C:\Users\John Hagen\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2583, in __init__ Widget.__init__(self, master, 'frame', cnf, {}, extra) File "C:\Users\John Hagen\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2131, in __init__ BaseWidget._setup(self, master, cnf) File "C:\Users\John Hagen\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2109, in _setup self.tk = master.tk AttributeError: 'Application' object has no attribute 'tk' -------------------- import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): super().__init__(self, master) self.pack() self.create_widgets() def create_widgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello World\n(click me)" self.hi_there["command"] = self.say_hi self.hi_there.pack(side="top") self.quit = tk.Button(self, text="QUIT", fg="red", command=root.destroy) self.quit.pack(side="bottom") def say_hi(self): print("hi there, everyone!") root = tk.Tk() app = Application(master=root) app.mainloop() ---------- Added file: http://bugs.python.org/file43641/0001-Fix-tkinter-docs-PEP8.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Berker Peksag added the comment: Thanks for the updated patch. I noticed a typo in your test script. It works for me if I update the super() line from super().__init__(self, master) to super().__init__(master) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Changes by John Hagen <johnthagen@gmail.com>: Removed file: http://bugs.python.org/file43641/0001-Fix-tkinter-docs-PEP8.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

John Hagen added the comment: @Berker, thanks for the tip! I've fixed it up. I think this latest patch covers everything Berker and Terry have commented about. ---------- Added file: http://bugs.python.org/file43645/Fix-tkinter-docs-PEP8.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

John Hagen added the comment: The patch was reviewed and marked ready to commit. Could someone with commit privileges perform the final commit? Thanks. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Roundup Robot added the comment: New changeset 453a88a41a58 by Berker Peksag in branch '3.5': Issue #27455: Improve examples in tkinter documentation https://hg.python.org/cpython/rev/453a88a41a58 New changeset 800c069e16a0 by Berker Peksag in branch 'default': Issue #27455: Merge from 3.5 https://hg.python.org/cpython/rev/800c069e16a0 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________

Berker Peksag added the comment: Since Terry is already busy with IDLE maintenance, I went ahead and commit the patch with minor modifications. Thanks for the patch, John! :) ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27455> _______________________________________
participants (5)
-
Berker Peksag
-
John Hagen
-
Roundup Robot
-
SilentGhost
-
Terry J. Reedy