KennisbankExamencentrum
NL · NLNederlands (Nederland)
Taal kiezen13

CKTIS / Python

typing.TypeAlias

Markeert een toewijzing voor de typecontrole als typealias.

Versie: Python 3.14; repository image, production runtime not attested

Syntax

Rows: TypeAlias = list[int]

Markeert een toewijzing voor de typecontrole als typealias.

Tijdens uitvoering blijft de rechterkant gebonden zonder nieuw type of validatie.

Sinds Python 3.12 is TypeAlias verouderd ten gunste van de type-instructie die een apart TypeAliasType-object maakt.

Voorbeelden

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)

Resultaat

True False
True True

Sinds Python 3.12 is TypeAlias verouderd ten gunste van de type-instructie die een apart TypeAliasType-object maakt.

Bronnen