Skip to content

gh-43457: Tkinter: fix design flaws in wm_attributes() #111404

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

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Oct 27, 2023

  • w.wm_attributes() without arguments returns a dict instead of a tuple or a str.
  • When called with a single argument to get a value, it allow to omit the minus prefix.
  • It can be called with keyword arguments to set attributes.

📚 Documentation preview 📚: https://cpython-previews--111404.org.readthedocs.build/

* w.wm_attributes() without arguments returns a dict instead of a tuple
  or a str.
* When called with a single argument to get a value, it allow to omit
  the minus prefix.
* It can be called with keyword arguments to set attributes.
@terryjreedy
Copy link
Member

terryjreedy commented Oct 28, 2023

To me, the changes are all good and at least a decade overdue. For instance, it upgrades w.wm_attributes to work like w.config. This issue comment gives more details.

The sticky part is immediately changing the return object of a no-arg call. This should be a plus for interactive uses and for new programmatic uses. However, it will break existing code that probes the structure of the return object.

The default requirement of PEP 387 is a deprecation period. The alternative (the last sentence): "If a warning cannot be provided to users, consult with the steering council." In this case, () cannot both give the old return with a warning and give the new return. So giving a warning would mean either not returning a dict until 3.15 (not nice) or temporarily requiring some temporary signal to get a dict. If None were intended to be used indefinitely to get the old return, the signal would have to be something else, like passing the dict class. (Yes, a bit ugly.)

I believe there is precedent to making an immediate change when the alternative is seen as worse. Part of the trade-off in such a decision would be knowing how common programmatic uses there are (and better, about how many of those would be broken). (There are core devs who have scripts to do such searches.) "Consulting with the security council" should begin with a post to the Python Core Dev discord.

(edit: sorry for the mis-click)

@serhiy-storchaka
Copy link
Member Author

@gpshead, I implemented your suggestion. Do you mind to review it?

@terryjreedy, please make yet one look at it.

@serhiy-storchaka serhiy-storchaka merged commit b4ba0f7 into python:main Feb 5, 2024
@serhiy-storchaka serhiy-storchaka deleted the tkinter-wm_attributes branch February 5, 2024 16:25
@terryjreedy
Copy link
Member

Sorry I did not get back to this. Looks like the best we could do under the costraints.

Copy link
Member

@gpshead gpshead left a comment

Choose a reason for hiding this comment

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

thanks for doing this!

fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
…H-111404)

* When called with a single argument to get a value, it allow to omit
  the minus prefix.
* It can be called with keyword arguments to set attributes.
* w.wm_attributes(return_python_dict=True) returns a dict instead of 
  a tuple (it will be the default in future).
* Setting wantobjects to 0 no longer affects the result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants