Replies: 1 comment 1 reply
-
All class objects are valid With this in mind, you can simplify your code to the following: def fn[**P, T](_type: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
return _type(*args, **kwargs)
x: X = fn(X, 123, "XYZ")
y: Y = fn(Y, 12.34) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a function that takes a generic type and constructs an instance of this type with arbitrary arguments specific to that type. Typing those
*args
and**kwargs
asAny
isn't very helpful, but I cannot seem to find the official way to pass constructor argument types into such function becauseParamSpec
requires aCallable
.I was able to accomplish what I'm looking for via this awkward syntax and wonder if anybody can suggest how to avoid using
Callable
for this.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions