Create type-annotations container for multiple variables

  mypy, python

I would like to create a DataFrame[T,..] type container that can hold multiple variables defined during type annotation like this:

UserId = DataFrame[int] #single

or

UserIdAndName = DataFrame[int, String] #multiple

And then be able to use these types anywhere types are allowed. Like def get_name(x: UserId) -> UserIdAndName.

I could get the first example working using Generics but how to allow for multiple parameters definition I only see that working using metaclasses + get_item slices but that breaks in mypy.

Any solution that is pythonic and does not break mypy?

Source: Python Questions

LEAVE A COMMENT