bjd2385 bjd2385 - 9 months ago 52
Python Question

What does typing.List<~T>[typing.Tuple[int]] mean in Python's typing lib?

While playing with Python's

module I came across something curious:

>>> from typing import List, Tuple
>>> List[Tuple[int]]

What's this Java-like syntax
? What does it mean?

Answer Source

Let's see:

  1. typing.List means a type from the typing library, named List
  2. <~T> means this type is generic, it's defined in terms of another type T
  3. [typing.Tuple[int]] means type T is the type Tuple[int].

In natural language, you can read the definition like this:

typing.List<~T>[typing.Tuple[int]]: a standard List of one-int tuples