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

Implement TypeMap to enable module specific type map registration #677

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

Conversation

hanjinliu
Copy link
Contributor

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.07%. Comparing base (058d63c) to head (a562cff).

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   89.16%   89.07%   -0.10%     
==========================================
  Files          39       39              
  Lines        4746     4780      +34     
==========================================
+ Hits         4232     4258      +26     
- Misses        514      522       +8     

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

@hanjinliu
Copy link
Contributor 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
Contributor Author

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

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.

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