Support Function With Multiple Generic Parameters Same Type

One variation that I think could be specified and implemented more precisely: Add a type qualifier that can wrap a TypeVar and means “do not use this usage of the TypeVar to add a constraint to the constraint solver”. Let’s call it NoConstraint.

It would behave like this:

def f[T](x: T, y: NoConstrain[T]): ...

def caller(i: int, o: object):
    x(i, 1)  # OK, T is solved to int, 1 is assignable to int
    x(i, o)  # error, T is solved to int, object is not assignable to int
    x(o, i)  # OK, T is solved to object

I think this would do what the OP wants and doesn’t rely on notions like the “first” usage.

I haven’t tried to actually implement it, though, and I don’t know if this is useful enough to add to the type system.

5 Likes