Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

typing.Final

Declare a name that a type checker should reject rebinding or overriding in a subclass.

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

Syntax

LIMIT: Final[int] = 3

Declare a name that a type checker should reject rebinding or overriding in a subclass.

Final protects the binding in static analysis and gives no deep immutability to the referenced object. Python itself still allows the assignment.

The program first mutates the same list and then replaces the binding with a different list.

Examples

from typing import Final

NAMES: Final[list[str]] = ["A"]
saved = NAMES
NAMES.append("B")
print(saved is NAMES, saved)
NAMES = ["C"]
print(saved, NAMES)

Result

True ['A', 'B']
['A', 'B'] ['C']

The program first mutates the same list and then replaces the binding with a different list.

Sources