Cannot use nested `Annotated` type
Closed this issue · 3 comments
Describe the bug
The recent update in make_annotated
makes it unable to interpret nested Annotated
types (although I'm not sure if "magicgui.signature" will still be used).
To Reproduce
Run this code.
from typing import Annotated
from magicgui import magicgui
@magicgui
def f(x: Annotated[Annotated[int, {"max": 5}], {"min": 0}]):
print(x)
Expected behavior
Annotated[Annotated[int, {"max": 5}], {"min": 0}]
should be interpreted as Annotated[int, {"max": 5, "min": 0}]
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
- OS: Windows 11
- backend: PyQt5
- magicgui version 0.7.0rc1
I have to admit... I've never encountered a nested annotated type. Is that a "just in case" thing? Or do you actively use that?
I actually use it a lot 😅
I have a lot of functions to be used as magicgui, so I usually define an Annotated type first, and add more configurations later, like below.
from magicgui import magicgui
from typing import Annotated
sliderInt = Annotated[int, {"widget_type": "Slider"}]
@magicgui
def f(x: Annotated[sliderInt, {"max": 5}]):
print(x)
@magicgui
def g(x: Annotated[sliderInt, {"max": 10}]):
print(x)
I'll send a PR later...
k.
ultimately, we need to move make_annotated
out of the signature module and make a more general annotated parsing logic that goes in type map... and merge it with the support for the annotated_types library starting here: https://github.com/pyapp-kit/magicgui/blob/9c36f9af0e79eefa0f8669747ea5e3b843ae979d/src/magicgui/schema/_ui_field.py#LL461-L493