Typing and Generics

typing.override

Signals that a method intentionally overrides a base-class member, enabling static checking of that relationship. Does not verify the relationship at runtime; attempts to set __override__. Added in 3.12.

Formal Syntax & Structure

python syntaxpython
@typing.override

Parameters & Attributes

NameTypeDescription
targetcallableObject to decorate.

Return Value

function

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import override
class Base:    def label(self)->str: return 'base'class Child(Base):    @override    def label(self)->str: return 'child'print((Child().label(),getattr(Child.label,'__override__',False)))
Python Reference