question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Annotated type

See original GitHub issue

Pulling 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tlambert03commented, Dec 22, 2020

implemented in #43@magicgui(arg={'min': 10, 'max': 100}) will continue to be the “promoted” API… but arg: Annotated[int, {'min': 10, 'max': 100}] = 50 will also work. moreover, the magicgui.signature.MagicParameter is a subclass of inspect.Parameter that bundles the widget options in an Annotated type in the Parameter.annotation

0reactions
tlambert03commented, Jul 16, 2020

this should be the fallback way to do this, while kwargs to magicgui should be the recommended way. … That’s the distinction I’m trying to make and one which I would hope magicgui would recommend…

understood 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 Annotated in an inspect.Signature as 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 use Annotated for GUI-specific things in their function signatures

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found