Closed tlambert03 closed 11 months ago
All modified lines are covered by tests :white_check_mark:
Comparison is base (
3aa4b81
) 87.85% compared to head (a322599
) 87.86%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hmm, I think this may have broken some downstream things. I believe adding an extra generic parameter to your classes changes the inheritance interface, because inheriting classes now have to add the corresponding parameter or it will be a runtime error: TypeError: Too few arguments for <class '__main__.Foo'>; actual 1, expected 2
. Happy to be convinced otherwise.
The commit in question is: https://github.com/pyapp-kit/magicgui/commit/05c92921a5a6e7dad3757557e73d09c2f559ac01
It would be helpful if you could include the code you ran with Foo
in it so I can see exactly what you're trying to do/inherit.
edit: are you using FunctionGui[...]
as a type hint? if so, I'd recommend just putting it in quotes or using __future__.annotations
... but show me your code and I can try to help further
This was happening with a class that inherited from FunctionGui
, but assuming it only had 1 type parameter. However I can't replicate this anymore. Even if I cram in far too many type parameters it doesn't throw an exception:
from magicgui.widgets import FunctionGui
class MyFunctionGui(FunctionGui[int, int, int, int, int, int]):
pass
ok... this is a complicated issue to be sure and I'm still trying to determine where you will and won't get the error:
But to provide some general high level hints:
you can always use FunctionGui without parametrizing the generic. It's optional, and only necessary for static type hinting... though it does have implications for runtime as well:
class MyFunctionGui(FunctionGui): ...
Since this is only necessary for static type hinting, and not part of the actual subclass inheritance requirements, you can also guard your subclass behind TYPE_CHECKING
from typing import TYPE_CHECKING, Generic, TypeVar
T = TypeVar("T")
class MyType(Generic[T]):
...
if TYPE_CHECKING:
mybase = MyType[int]
else:
mybase = MyType
class MySub(mybase):
...
bringing it back to something concrete. Why don't you tell me more specifically where you're running into this error. link to a repo if you have one... and I'll try to help you come up with a static typing solution you're happy with, but for runtime, none of this is necessary. magicgui does need to be able to update its static typing interface, and there's really no way to deprecate that. So this change isn't going to be reverted... but there are ways that you can support both old/new magicgui at runtime and achieve any static typing you want to (though for that you'll need to run mypy assuming certain versions of magicgui).
thanks!
This PR uses ParamSpec to preserve function type hints when decorated with
@magicgui
before this PR:
after: