With mypy, are there any ways to get the type of `T` in a generic function?

Generic functions are not yet supported in Python’s typing system.

You can read about the ongoing effort to make it happen at PEP 718: subscriptable functions.