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

feat: Implement TypeMap to enable module specific type map registration #677

Merged
merged 4 commits into from
Nov 9, 2024

Conversation

hanjinliu
Copy link
Collaborator

Closes #676

(I said WidgetStore in the issue but it turned out that there were more things to store so I simply named it TypeMap 🥲 )
All the functions that used the global type map before are now referring to the global instance of TypeMap.

Example:

from magicgui.type_map import TypeMap
from magicgui.widgets import Slider
from magicgui import magicgui

mymap = TypeMap()
mymap.register_type(int, widget_type=Slider)

@magicgui
def func(x: int): ...  # <- x is SpinBox, as usual

@mymap.magicgui
def func(x: int): ...  # <- x is Slider

Some functions, such as magicgui and create_widget, no longer need to be in the files they used to be, but they are still in the original files in case some users use private import such as from magicgui.type_map._magicgui import magicgui. Probably we need some refactoring in the future because there are some dirty import statements inside functions to avoid circular import.

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 95.96774% with 10 lines in your changes missing coverage. Please review.

Project coverage is 89.00%. Comparing base (674094f) to head (519c139).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/magicgui/type_map/_type_map.py 95.96% 9 Missing ⚠️
src/magicgui/type_map/_magicgui.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #677      +/-   ##
==========================================
+ Coverage   88.97%   89.00%   +0.03%     
==========================================
  Files          39       39              
  Lines        4743     4777      +34     
==========================================
+ Hits         4220     4252      +32     
- Misses        523      525       +2     

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

@hanjinliu
Copy link
Collaborator Author

It seems pint has some problem with dataclass (see here).

@Czaki
Copy link
Contributor

Czaki commented Nov 7, 2024

The current problem is caused by flexparser 0.4 release: hgrecco/flexparser#12

@hanjinliu
Copy link
Collaborator Author

Ah, that's why all the tests including python<3.13 are failing.

@tlambert03
Copy link
Member

flexparser is fixed ... could you merge conflicts now that #671 is merged?

@hanjinliu
Copy link
Collaborator Author

Is the failed test a random connection error? Everything is working as expected :)

Copy link
Member

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

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

this is excellent work @hanjinliu! thank you so much.

@tlambert03 tlambert03 merged commit a5669e3 into pyapp-kit:main Nov 9, 2024
36 checks passed
@tlambert03 tlambert03 changed the title Implement TypeMap to enable module specific type map registration feat: Implement TypeMap to enable module specific type map registration Nov 9, 2024
@tlambert03 tlambert03 added the enhancement New feature or request label Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WidgetStore for module specific type-to-widget mapping
3 participants