Replies: 1 comment 3 replies
-
I think the order of the decorators might be what's tripping mypy up here, Also if I may suggest some simplifications, you are overusing The following looks more correct to me: @overload
def depends(
*dependencies: str, watch: bool = ..., on_init: bool = ...
) -> Callable[[CallableT], DependsFunc[CallableT]]:
...
@overload
def depends(
*dependencies: Parameter, watch: bool = ..., on_init: bool = ..., **kw: Parameter
) -> Callable[[CallableT], DependsFunc[CallableT]]:
...
@accept_arguments
def depends(
func: CallableT, *dependencies: Dependency, watch: bool = False, on_init: bool = False, **kw: Parameter
) -> DependsFunc[CallableT]: |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a draft annotations PR here: https://github.com/holoviz/param/pull/959/files
This is a tricky one, and I can't tell if I'm doing something wrong or if this is a bug.
There are multiple decorators here:
depends
takes afunc
and several extra parameters. It is not valid as a decorator by itself because of those extra parameters.accept_arguments
on top of it, it becomes a second-order decorator (takes parameters and returns a first-order decorator).This is further complicated by the fact that not all parameter combinations of
depends
are valid, and so I use@overload
to only support valid combinations. I have found some old Mypy PRs that confirm that combining a decorator with@overload
is supported.Here's what running
mypy
on thedepends.py
file produces:I'm kind of stumped here, I've been staring at this for a bit and I don't see anything wrong.
Beta Was this translation helpful? Give feedback.
All reactions