Skip to content

Commit 9b66e92

Browse files
authored
Support nested Annotated types (#536)
1 parent 9c36f9a commit 9b66e92

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/magicgui/signature.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ def make_annotated(annotation: Any = Any, options: dict | None = None) -> Any:
5454
_options = (options or {}).copy()
5555

5656
if get_origin(annotation) is Annotated:
57-
annotation, anno_options = get_args(annotation)
58-
_options.update(anno_options)
57+
# nested Annotated type results in multiple dicts.
58+
annotation, *anno_options = get_args(annotation)
59+
for opt in anno_options:
60+
if not isinstance(opt, dict):
61+
raise TypeError("Every Annotated option must be a dict")
62+
_options.update(opt)
5963
return Annotated[annotation, _options]
6064

6165

tests/test_types.py

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def test_pick_widget_builtins_forward_refs(cls, string):
5252
Annotated[float, {"widget_type": "FloatSlider", "step": 9}],
5353
widgets.FloatSlider,
5454
),
55+
(
56+
Annotated[Annotated[int, {"widget_type": "Slider"}], {"max": 10}],
57+
widgets.Slider,
58+
),
5559
],
5660
)
5761
def test_annotated_types(hint, expected_wdg):

0 commit comments

Comments
 (0)