CKTIS / Python
typing.TypeAlias
Segnala al verificatore un’assegnazione come alias di tipo.
Versione: Python 3.14; repository image, production runtime not attested
Sintassi
Rows: TypeAlias = list[int]Segnala al verificatore un’assegnazione come alias di tipo.
In esecuzione il nome indica il membro destro senza creare un tipo distinto o validare valori.
Da Python 3.12 TypeAlias è deprecato a favore dell’istruzione type che crea un oggetto TypeAliasType separato.
Esempi
from typing import TypeAlias, TypeAliasType
Rows: TypeAlias = list[int]
type NewRows = list[int]
print(Rows == list[int], isinstance(Rows, TypeAliasType))
print(isinstance(NewRows, TypeAliasType), NewRows.__value__ == Rows)
Risultato
True False True True
Da Python 3.12 TypeAlias è deprecato a favore dell’istruzione type che crea un oggetto TypeAliasType separato.