Add support for Annotated type
See original GitHub issuePulling out this great tip by @VolkerH from https://github.com/napari/magicgui/issues/20#issuecomment-647888706 into a new issue. We can use the Annotated type (PEP 593) available through typing_extensions for parameter-specific metadata.
so, as demonstrated by @jni in https://github.com/napari/magicgui/issues/20#issuecomment-648504543, we could put argument-specific options directly in the type hint:
@magicgui(arg={'minimum': 10, 'maximum': 100})
def my_func(arg=50): ...
# could become this:
@magicgui
def my_func(arg: Annotated[int, {'minimum': 10, 'maximum': 100}] = 50): ...
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
typing — Support for type hints — Python 3.11.1 documentation
The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers,...
Read more >Add support for Annotated type · Issue #34 · napari/magicgui
We can use the Annotated type (PEP 593) available through typing_extensions for parameter-specific metadata. so, as demonstrated by @jni in #20 (comment), we ......
Read more >Type Annotations and Pluggable Type Systems
Type annotations were created to support improved analysis of Java programs ... In this way, you can build on top of the Java...
Read more >Improve code inspection with annotations - Android Developers
Add the support annotations library dependency; Run code inspections ... Annotations for the other resource types, such as @DrawableRes , @DimenRes ...
Read more >Understanding type annotation in Python - LogRocket Blog
In this extensive post with specific examples, learn how to use Python type annotation to your advantage using the mypy library.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

implemented in #43 …
@magicgui(arg={'min': 10, 'max': 100})will continue to be the “promoted” API… butarg: Annotated[int, {'min': 10, 'max': 100}] = 50will also work. moreover, themagicgui.signature.MagicParameteris a subclass ofinspect.Parameterthat bundles the widget options in anAnnotatedtype in theParameter.annotationunderstood and totally agree. “magicgui” will recommend that 😃
I think I’m probably focusing (in my head) a bit more at the moment on the usefulness of
Annotatedin aninspect.Signatureas the internal representation that magicgui would use to pass around this info, in which case “supporting” it here would be trivial. but I definitely agree, I wouldn’t want to start changing all the examples to encourage people to useAnnotatedfor GUI-specific things in their function signatures