Reject invalid ParamSpec locations by sterliakov · Pull Request #18278 · python/mypy (original) (raw)
I see, so main issue is not being able to statically type it since function could be called differently, thanks.
I guess my actual use case is a bit different?
@dataclasses.dataclass(slots=True, kw_only=True, frozen=True) class TaskInstance(Generic[P, TResult]): task: TaskDefinition[P, TResult] args: P.args kwargs: P.kwargs
@dataclasses.dataclass(kw_only=True) class TaskDefinition(Generic[P, TResult]): func: Callable[P, Awaitable[TResult]]
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> TaskInstance[P, TResult]:
return TaskInstance(
task=self,
args=args,
kwargs=kwargs,
)
This seems ok since we know which arguments were used when creating instance of TaskInstance
, but I guess if it's currently not supported or isn't planned I'll just type it as tuple[object, ...], dict[str, object]
or something like that 😅