Using ParamSpec as an argument to a Generic type #1289
Unanswered
ciupakabra
asked this question in
Q&A
Replies: 1 comment 2 replies
-
There are a number of problems in this code. First, Is I'm not sure I fully understand what your intent is with this code, but perhaps this is what you're looking to do? from typing import Callable, TypeVar, Generic, ParamSpec
T = TypeVar("T")
P = ParamSpec("P")
class Container(Generic[T]):
def __init__(self, x: T):
self.x = x
def map(f: Callable[P, T]) -> Callable[P, Container[T]]:
def inner(*args: P.args, **kwargs: P.kwargs) -> Container[T]:
return Container(f(*args, **kwargs))
return inner |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to correctly type a
map
function for a pretty straightforward type?Currently mypy prints
Having seen the discussion #1163 , I'm assuming the answer is no, but I don't understand that discussion fully so would appreciate some help.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions