Python Glossary Русский

Python 3.12+typingfunction

typing.override

decorators and markers

A decorator marking a method as overriding a base-class method; a type checker verifies that the parent really has such a method (Python 3.12+).

Syntax

@typing.override

At runtime it's a no-op (it just sets an __override__ attribute); the value is entirely for the type checker. It catches the classic bug where a base-class method is renamed or removed and your "override" silently becomes a new, unrelated method — without @override nothing flags it.

Examples

from typing import override
class Base:
    def f(self): ...
class Sub(Base):
    @override
    def f(self): return 42
print(Sub().f())   # → 42

See also

Open in the full glossarydocs.python.orgReport an inaccuracy