Skip to content

gh-126008: Improve docstrings for Tkinter cget and configure methods #133303

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented May 2, 2025

  • Explain the behavior of Widget.configure() depending on arguments.
  • Unify descriptions.
  • Replace "resource" with "option".

…thods

* Explain the behavior of Widget.configure() depending on arguments.
* Unify descriptions.
* Replace "resource" with "option".
option(s) to have the given value(s); in this case the
command returns an empty string. The following options
are supported:
"""Query or modify the configuration options for window TAGORID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to understand what TAGORID meant, maybe it'd be better if we match the parameter name, i.e. use tarOrId (and similar for the other cases)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I indicated elsewhere, I think the raw test should be *tagOrID* as italicizing option names is better than all-capping them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In THIS file, capitalization is used for parameter names. It is not ideal, but we should be consistent.

return self.tk.call(
(self._w, 'itemcget') + (tagOrId, '-'+option))

def itemconfigure(self, tagOrId, cnf=None, **kw):
"""Configure resources of an item TAGORID.
"""Query or modify the configuration options of an item TAGORID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Query or modify the configuration options of an item TAGORID.
"""Query or modify the configuration options of item *tagOrID*.

Just remembered that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://peps.python.org/pep-0257/#multi-line-docstrings says "Do not use the Emacs convention of mentioning the arguments of functions or methods in upper case in running text. Python is case sensitive and the argument names can be used for keyword arguments, so the docstring should document the correct argument names." 'tagOrID' is an example of why not. It goes on to suggest " It is best to list each argument on a separate line. For example:..." but this tends to bloat the doc. Don't add *s if you do not want, but please drop the all caps at least here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using different convention for different methods will do more harm than good. This is a different issue, we will change the convention after fixing all docstrings.

option(s) to have the given value(s); in this case the
command returns an empty string. The following options
are supported:
"""Query or modify the configuration options for window TAGORID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I indicated elsewhere, I think the raw test should be *tagOrID* as italicizing option names is better than all-capping them.

@bedevere-app
Copy link

bedevere-app bot commented May 3, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
@serhiy-storchaka serhiy-storchaka requested a review from a team May 13, 2025 10:36
under Tk.

Widgets are positioned with one of the geometry managers Place, Pack
or Grid. These managers can be called with methods place, pack, grid
available in every Widget.

Actions are bound to events by resources (e.g. keyword argument
command) or with the method bind.
Actions are bound to events by options (e.g. the command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this, or "command" should be a docs cross-reference.

Suggested change
Actions are bound to events by options (e.g. the command
Actions are bound to events by options (e.g., the *command*

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted this before seeing the discussion about omitting formatting from docstrings. This should be consistent with whatever is decided.

Actions are bound to events by resources (e.g. keyword argument
command) or with the method bind.
Actions are bound to events by options (e.g. the command
keyword argument) or with the bind() method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is right; or, it should be inserted as a docs crossref if possible:

Suggested change
keyword argument) or with the bind() method.
keyword argument) or with the *bind()* method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted this before seeing the discussion about omitting formatting from docstrings. This should be consistent with whatever is decided.

@@ -847,7 +847,7 @@ def tk_focusNext(self):
The focus order first goes to the next child, then to
the children of the child recursively and then to the
next sibling which is higher in the stacking order. A
widget is omitted if it has the takefocus resource set
widget is omitted if it has the takefocus option set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting, or crossref if possible:

Suggested change
widget is omitted if it has the takefocus option set
widget is omitted if it has the *takefocus* option set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted this before seeing the discussion about omitting formatting from docstrings. This should be consistent with whatever is decided.

The values for resources are specified as keyword
arguments. To get an overview about
the allowed keyword arguments call the method keys.
If no arguments is specified, return a dictionary describing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If no arguments is specified, return a dictionary describing
If no arguments are specified, return a dictionary describing


Option may be any value allowed by the paneconfigure subcommand
"""
"""Return the value of option for window."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the parameter naming here. The method only has a child param... perhaps something like:

Suggested change
"""Return the value of option for window."""
"""Return the value of option for a the window child."""

Understandability here would definitely benefit from adding formatting, as long as it would render in the docs: *child*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants