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 overridesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `@override` decorator with the `EnforceOverrides` metaclass. The `Animal` class defines methods, and `Dog` subclasses it, using `@override` to explicitly mark overridden methods. If `EnforceOverrides` is used, methods intended to override a superclass method *must* use the `@override` decorator, otherwise a `TypeError` will be raised at class creation time. The library also automatically copies docstrings from the overridden method.
Update exception handling to catch `TypeError` instead of `AssertionError` for issues related to `EnforceOverrides` or `final` magic method overrides.
Upgrade to `overrides` version 7.6.0 or newer to ensure compatibility and correct bytecode handling with Python 3.12.
Ensure `@classmethod` or `@staticmethod` is the outermost decorator, followed by `@override`. Example: `@classmethod @override def my_method(cls, ...):`
Prefer using `from overrides import override` and the `@override` decorator for new code. Update existing code to use `@override` for consistency.
Always decorate methods in subclasses with `@override` if they are meant to override a method from a base class that uses `EnforceOverrides`.
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 the 'overrides' library using pip: 'pip install overrides'.
Ensure you are using the correct import statement: 'from overrides import override'.
Use the 'override' decorator with parentheses: '@override()'.
Ensure you are using the correct import statement: 'from overrides import EnforceOverrides'.
Use the 'override' decorator with the '@' symbol: '@override'.
No dependency data recorded yet.