Overrides Library
raw JSON → 7.7.0 verified Tue May 12 auth: no python install: verified quickstart: verified
The `overrides` library (v7.7.0) provides a Python decorator `@override` to ensure that a method in a subclass correctly overrides a method from its superclass. It also includes `EnforceOverrides` for metaclass-level checks and `@final` to prevent methods from being overridden. The library focuses on improving the safety and experience of creating class hierarchies by catching common errors at class creation time, such as signature mismatches or accidental non-overrides. It has a regular release cadence, with several minor and patch releases in the past year.
pip install overrides Common errors
error ModuleNotFoundError: No module named 'overrides' ↓
cause The 'overrides' library is not installed in the Python environment.
fix
Install the 'overrides' library using pip: 'pip install overrides'.
error ImportError: cannot import name 'override' from 'overrides' ↓
cause The 'override' decorator is not available in the 'overrides' module.
fix
Ensure you are using the correct import statement: 'from overrides import override'.
error TypeError: 'override' object is not callable ↓
cause The 'override' decorator is being used incorrectly, possibly without parentheses.
fix
Use the 'override' decorator with parentheses: '@override()'.
error AttributeError: module 'overrides' has no attribute 'EnforceOverrides' ↓
cause The 'EnforceOverrides' metaclass is not available in the 'overrides' module.
fix
Ensure you are using the correct import statement: 'from overrides import EnforceOverrides'.
error SyntaxError: unexpected EOF while parsing ↓
cause The 'override' decorator is used without the '@' symbol.
fix
Use the 'override' decorator with the '@' symbol: '@override'.
Warnings
breaking In version 7.0.0, the library changed how it handles `final` magic methods and assertion failures. Magic methods (e.g., `__eq__`, `__init__`) marked as `@final` that are accidentally overridden now raise `TypeError` instead of `AssertionError`. Similarly, assertion errors originating from the `EnforceOverrides` metaclass have been changed to `TypeErrors`. This may break existing tests or error handling code that specifically caught `AssertionError`. ↓
fix Update exception handling to catch `TypeError` instead of `AssertionError` for issues related to `EnforceOverrides` or `final` magic method overrides.
gotcha Versions prior to 7.6.0 might experience issues with Python 3.12 due to changes in bytecode handling. This could lead to unexpected behavior or runtime errors on Python 3.12 environments. ↓
fix Upgrade to `overrides` version 7.6.0 or newer to ensure compatibility and correct bytecode handling with Python 3.12.
gotcha When combining `@override` with other method decorators like `@classmethod` or `@staticmethod`, the `@classmethod` or `@staticmethod` decorator must always be applied *before* `@override`. Incorrect order will lead to unexpected behavior or errors. ↓
fix Ensure `@classmethod` or `@staticmethod` is the outermost decorator, followed by `@override`. Example: `@classmethod
@override
def my_method(cls, ...):`
deprecated The original decorator name `@overrides` (plural) is still functional, but `@override` (singular) was introduced in version 7.3.0 as an alias and is now the officially recommended decorator name, aligning with common usage and `typing.override`. ↓
fix Prefer using `from overrides import override` and the `@override` decorator for new code. Update existing code to use `@override` for consistency.
gotcha If a base class inherits from `EnforceOverrides`, any method in a subclass that is intended to override a superclass method *must* be explicitly decorated with `@override` (or `@overrides`). Failing to do so will result in a `TypeError` at class definition time, preventing subtle bugs caused by method signature changes in parent classes. ↓
fix Always decorate methods in subclasses with `@override` if they are meant to override a method from a base class that uses `EnforceOverrides`.
gotcha Python 3.12 introduced a standard `typing.override` decorator (PEP 698) for static type checkers. The `overrides` library's `@override` provides *runtime* validation and docstring inheritance, which is distinct from `typing.override`'s static analysis purpose. Using both might be confusing but they serve different roles. ↓
fix Understand the difference: `overrides.override` provides runtime checks and features, while `typing.override` is purely for static analysis. Choose based on whether you need runtime enforcement or only static type checking.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.02s 17.9M
3.10 alpine (musl) - - 0.02s 17.9M
3.10 slim (glibc) wheel 1.5s 0.01s 18M
3.10 slim (glibc) - - 0.01s 18M
3.11 alpine (musl) wheel - 0.05s 19.7M
3.11 alpine (musl) - - 0.05s 19.7M
3.11 slim (glibc) wheel 1.6s 0.04s 20M
3.11 slim (glibc) - - 0.04s 20M
3.12 alpine (musl) wheel - 0.05s 11.6M
3.12 alpine (musl) - - 0.05s 11.6M
3.12 slim (glibc) wheel 1.5s 0.05s 12M
3.12 slim (glibc) - - 0.05s 12M
3.13 alpine (musl) wheel - 0.04s 11.3M
3.13 alpine (musl) - - 0.05s 11.2M
3.13 slim (glibc) wheel 1.5s 0.04s 12M
3.13 slim (glibc) - - 0.04s 12M
3.9 alpine (musl) wheel - 0.02s 17.4M
3.9 alpine (musl) - - 0.02s 17.4M
3.9 slim (glibc) wheel 1.8s 0.02s 18M
3.9 slim (glibc) - - 0.02s 18M
Imports
- override
from overrides import override - overrides
from overrides import overrides - EnforceOverrides wrong
from overrides import overridescorrectfrom overrides import EnforceOverrides - final
from overrides import final
Quickstart verified last tested: 2026-04-24
from overrides import override, EnforceOverrides
class Animal(EnforceOverrides):
def make_sound(self) -> str:
raise NotImplementedError
def eat(self) -> str:
return "Eating generic food"
class Dog(Animal):
@override
def make_sound(self) -> str:
return "Woof!"
# No @override needed if not overriding a method, or if EnforceOverrides is not used.
def fetch(self) -> str:
return "Fetching the ball"
# Example of usage
dog = Dog()
print(dog.make_sound())
print(dog.eat())
# This would raise TypeError if @override was missing on make_sound and EnforceOverrides was used.
# class Cat(Animal):
# def make_sound(self) -> str: # Missing @override, would fail with EnforceOverrides
# return "Meow!"