Support for ParamSpec
for type
#1991
Labels
topic: feature
Discussions about new features for Python's type annotations
8000
ParamSpec
for type
#1991
The problem I'm having is that the
type
doesn't supportParamSpec
, so I can't use that to enforceargs
andkwargs
, in the same way as asCallable
. I'm not 100% sure whether this is correct, but isn't everytype
aCallable
, so in a sense thattype
is a subtype ofCallable
, so there should be a way to representtype
in the same way as aCallable
to obey Liskov?For example, I'm trying to write an overload such that passing in a
type
will returnExpectType
, while a generalCallable
returnsExpectCallable
:As you can see that
t.assert_type(expect(A), ExpectType[[], A])
passes with no errors, even thoughA
is suppose to take in astr
argument. I'm expectingexpect(A)
to require astr
argument, similar to howexpect(fn, "inp")
requires the second parameter"inp"
.Note that I haven't used
*args
and**kwargs
in the example for simplicity, but they are meant to be used inside of theExpect
classes.Maybe the simplest way is to add a new class
TypeCallable
that allows forTypeCallable[P, T]
instead of modifyingtype
, so the above example is achievable:Note that I think #1966 might also solve the above problem.
The text was updated successfully, but these errors were encountered: