> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Override Decorator

The `@override` decorator, introduced in Python 3.12 (PEP 698) within the `typing` module, is a static analysis directive used to explicitly declare that a method in a subclass is intended to replace a method or attribute defined in its Method Resolution Order (MRO).

When applied, it instructs static type checkers (such as `mypy` or `pyright`) to verify the existence of a matching member in a base class. If the base class lacks a corresponding member, or if the signature is incompatible, the type checker emits an error.

```python theme={"dark"}
from typing import override

class Base:
    def process_data(self, data: str) -> bool:
        pass

    @property
    def status(self) -> str:
        return "pending"

class SubClass(Base):
    @override
    def process_data(self, data: str) -> bool:
        return True
```

## Technical Characteristics

* **Runtime Behavior:** At runtime, the decorator attempts to set the `__override__` attribute on the decorated callable to `True` (e.g., `arg.__override__ = True`) before returning it. This design choice allows runtime libraries and introspection tools to inspect the attribute. It does not, however, alter method resolution or enforce overriding during execution.
* **Static Validation:** Enforcement is strictly delegated to static analysis tools. The Python interpreter will not raise an `Exception` or `TypeError` at runtime if an `@override`-decorated method fails to actually override a base class method.
* **Signature Compatibility:** Type checkers validate both the method name and the type signature. The overriding method must accept arguments and return types that are structurally compatible with the base method (contravariant for arguments, covariant for return types).
* **Target Scope & Decorator Stacking:** It can be applied to standard instance methods, as well as methods decorated with `@classmethod`, `@staticmethod`, and `@property`. When stacking decorators, `@override` must be the **outermost** decorator (furthest from the `def` statement). Because wrapper objects like `property` or `classmethod` do not support arbitrary attribute assignment, `typing.override` is explicitly designed with an internal `try/except` block. This silently catches and ignores `AttributeError` or `TypeError` at runtime, allowing it to safely wrap other decorators while satisfying static type checker requirements.
* **Backwards Compatibility:** For Python environments running versions prior to 3.12, the exact same decorator functionality is available by importing from the third-party `typing_extensions` package.

```python theme={"dark"}

# Python < 3.12 compatibility
from typing_extensions import override

class LegacySubClass(Base):
    @override
    @property
    def status(self) -> str:
        return "active"
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
