1 - Union vs TypeVar
On the left, the imaginary example program would crash on the lines 8 and 9. Mypy could not help with it. On the right, mypy would complain about the lines 8 and 9, which is probably what we want. So, TypeVar is a better choice if the type must be consistent across multiple uses within a given scope.
Read more
- TypeVar official docs: https://docs.python.org/3/library/typing.html#typing.TypeVar