Skip to content
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

API consistency: switch widget #1526

Merged
merged 9 commits into from Jul 27, 2022
Merged

API consistency: switch widget #1526

merged 9 commits into from Jul 27, 2022

Conversation

bruno-rino
Copy link
Contributor

@bruno-rino bruno-rino commented Jul 15, 2022

The Switch widget API becomes more consistent with other widgets by renaming some properties:

  • label -> text
  • is_on -> value
  • on_toggle -> on_change

The legacy API still works, with deprecation warnings. Exceptions are raised if both the new and old init parameters are used. The label text parameter, now called text, was temporarily changed to keyword argument. It should be changed back to positional argument when the compatibility code is removed.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

For the most part, this looks great - it's all fairly mechanical renames in the demos and the backends. The only real comments I have are in the core interface - and those pretty much all relate to making it easy for the future PR that removes the backwards compatibility shim.

src/core/toga/widgets/switch.py Outdated Show resolved Hide resolved
src/core/toga/widgets/switch.py Show resolved Hide resolved
src/core/toga/widgets/switch.py Outdated Show resolved Hide resolved
src/core/toga/widgets/switch.py Outdated Show resolved Hide resolved
…at it is easier to remove

Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
@bruno-rino
Copy link
Contributor Author

It's my first time updating a PR. Let me know if I did something wrong.

@bruno-rino
Copy link
Contributor Author

I'm not clear on how to move forward. Should I "Resolve Conversation", to signal that I addressed the changes requested? When these changes are OK, I'll carry on with the other changes laid out in #1521. Should I open new PR for those, or append to this PR?

@freakboy3742
Copy link
Member

@bruno-rino Apologies for not responding earlier - I missed the update when you pushed the extra code. As an aside - if you've got a PR where you've made an update and you've been waiting for a review and haven't heard anything for a couple of days, don't be afraid to give a gentle nudge. Sometimes there will be a reason that we haven't responded, but more often than not, it's a simple case of missing a notification that a PR update is ready for review.

Generally speaking, we prefer if the person who opens the conversation resolves it (on the basis that the person who raises a point is the person who can judge if the point has been addressed).

In terms of PR process - the general guidance is "one idea per PR", and try to keep that idea as small as possible. Keeping the PRs small makes them easier to review, which means the review/merge cycle is faster, and there's less chance of a PR turning into a multi-month epic with weekly merge collisions to resolve. In this case "clean up the Switch widget" is a good target"; Something like "use .value consistently" would probably be on the larger side, but probably just under the "one idea" limit. A single "make the Toga API consistent" PR would be way too large to be practical.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

I've made a couple of minor cosmetic tweaks, including addressing the problem around detecting is_on and value both being specified, and a couple of old API uses in the demos - but otherwise, this looks great! Thanks for the contribution!

enabled (bool): Whether or not interaction with the button is possible, defaults to `True`.
factory (:obj:`module`): A python module that is capable to return a
implementation of this class with the same name. (optional & normally not needed)
"""

def __init__(
self,
label,
text=None, # BACKWARDS COMPATIBILITY: change to positional argument when the deprecated `label` is removed
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 moment to work out what this comment was referring to; it wasn't until I stumbled over an old usage in the canvas demo that it became clear.

I can now see that this is to make toga.Switch(label='foo') legal. This is definitely needed, but we're also going to need an additional protection, because as written, toga.Switch() is legal.

on_change = on_toggle
# is_on replaced with value
if is_on is not None:
# Note: since `value` has a default, there is no defense against setting both `value` and `is_on`
Copy link
Member

Choose a reason for hiding this comment

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

We can add that defence though; you use a placeholder other than None, and check for that.

@freakboy3742
Copy link
Member

freakboy3742 commented Jul 26, 2022

The test failure is caused by sphinx-doc/sphinx#10705 - a fix for that should land very soon. I'll force a re-run of the test suite once that lands.

@codecov
Copy link

codecov bot commented Jul 26, 2022

Codecov Report

Merging #1526 (98b1a40) into main (a0788a9) will increase coverage by 0.03%.
The diff coverage is 98.58%.

Impacted Files Coverage Δ
src/core/tests/widgets/test_switch.py 97.00% <97.40%> (-1.00%) ⬇️
src/core/toga/widgets/switch.py 100.00% <100.00%> (ø)
src/dummy/toga_dummy/widgets/switch.py 100.00% <100.00%> (ø)

@freakboy3742 freakboy3742 merged commit 95ceebd into beeware:main Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants