bjd2385 bjd2385 - 1 year ago 89
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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download