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

fix: fix Literal with widget_type #586

Merged
merged 1 commit into from
Sep 23, 2023
Merged

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Sep 22, 2023

fixes #585 where providing widget_type didn't get to the parsing of Literal

Summary by CodeRabbit

  • New Feature: Enhanced support for Literal type annotations in the magicgui type map. The update introduces a function that correctly extracts choices and nullable flags from Literal types, improving the accuracy of widget selection.
  • Test: Added a new test case test_pick_widget_literal() to ensure the correct widget class is returned for Literal annotations and that the choices are accurately extracted.

@coderabbitai
Copy link

coderabbitai bot commented Sep 22, 2023

Walkthrough

This change introduces a new function to handle Literal type annotations in the magicgui type map. It refactors existing logic for cleaner code and adds a test case to verify the correct widget selection and choice extraction from Literal annotations.

Changes

File Summary
src/magicgui/type_map/... Introduced _literal_choices function to extract choices and nullable flag from Literal type annotation. Refactored match_type and _pick_widget_type functions for cleaner handling of Literal types.
tests/test_types.py Added test_pick_widget_literal() test case to verify correct widget class selection and choice extraction from Literal annotations.

🐇💻

In the land of code, where the brackets lie,
A rabbit hopped forth, with a twinkle in its eye.
"A Literal here, a Literal there,
With my new function, I handle them with care.
Now the code is clean, the tests are green,
Oh, what a wonderful coding scene!" 🎉🥕


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between b82b3c8 and f9b8901.
Files selected for processing (2)
  • src/magicgui/type_map/_type_map.py (3 hunks)
  • tests/test_types.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/magicgui/type_map/_type_map.py
Additional comments (Suppressed): 1
tests/test_types.py (1)
  • 192-199: The new test case test_pick_widget_literal() is well written and covers the changes made in the type map file. It checks whether the correct widget class (widgets.RadioButtons) is returned for a Literal annotation and whether the choices are correctly extracted from the Literal annotation. This addition enhances the test coverage for the changes made in the type map file.

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (b82b3c8) 87.61% compared to head (f9b8901) 87.61%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #586   +/-   ##
=======================================
  Coverage   87.61%   87.61%           
=======================================
  Files          39       39           
  Lines        4528     4538   +10     
=======================================
+ Hits         3967     3976    +9     
- Misses        561      562    +1     
Files Changed Coverage Δ
src/magicgui/type_map/_type_map.py 96.15% <100.00%> (-0.28%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tlambert03 tlambert03 merged commit 2760ae7 into pyapp-kit:main Sep 23, 2023
31 of 33 checks passed
@tlambert03 tlambert03 deleted the fix-literal branch September 23, 2023 01:53
@tlambert03 tlambert03 added the bug Something isn't working label Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Literal and widget_type="RadioButtons" not compatible
1 participant