{"id":676,"library":"overrides","title":"Overrides Library","description":"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.","status":"active","version":"7.7.0","language":"python","source_language":"en","source_url":"https://github.com/mkorpela/overrides","tags":["utility","decorator","type-checking","oop","inheritance","runtime-check","validation"],"install":[{"cmd":"pip install overrides","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"This is the recommended alias for the decorator since version 7.3.0.","symbol":"override","correct":"from overrides import override"},{"note":"The original name of the decorator, still functional but `@override` is preferred.","symbol":"overrides","correct":"from overrides import overrides"},{"note":"This is a metaclass, not a decorator, used to enforce `@override` usage.","wrong":"from overrides import overrides","symbol":"EnforceOverrides","correct":"from overrides import EnforceOverrides"},{"note":"Use `typing.final` directly for Python 3.11+; `overrides.final` provides a backport for older versions.","symbol":"final","correct":"from overrides import final"}],"quickstart":{"code":"from overrides import override, EnforceOverrides\n\nclass Animal(EnforceOverrides):\n    def make_sound(self) -> str:\n        raise NotImplementedError\n\n    def eat(self) -> str:\n        return \"Eating generic food\"\n\nclass Dog(Animal):\n    @override\n    def make_sound(self) -> str:\n        return \"Woof!\"\n    \n    # No @override needed if not overriding a method, or if EnforceOverrides is not used.\n    def fetch(self) -> str:\n        return \"Fetching the ball\"\n\n# Example of usage\ndog = Dog()\nprint(dog.make_sound())\nprint(dog.eat())\n\n# This would raise TypeError if @override was missing on make_sound and EnforceOverrides was used.\n# class Cat(Animal):\n#     def make_sound(self) -> str: # Missing @override, would fail with EnforceOverrides\n#         return \"Meow!\"","lang":"python","description":"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."},"warnings":[{"fix":"Update exception handling to catch `TypeError` instead of `AssertionError` for issues related to `EnforceOverrides` or `final` magic method overrides.","message":"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`.","severity":"breaking","affected_versions":"7.0.0 and later"},{"fix":"Upgrade to `overrides` version 7.6.0 or newer to ensure compatibility and correct bytecode handling with Python 3.12.","message":"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.","severity":"gotcha","affected_versions":"<7.6.0"},{"fix":"Ensure `@classmethod` or `@staticmethod` is the outermost decorator, followed by `@override`. Example: `@classmethod\n@override\ndef my_method(cls, ...):`","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer using `from overrides import override` and the `@override` decorator for new code. Update existing code to use `@override` for consistency.","message":"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`.","severity":"deprecated","affected_versions":"7.3.0 and later"},{"fix":"Always decorate methods in subclasses with `@override` if they are meant to override a method from a base class that uses `EnforceOverrides`.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"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.","severity":"gotcha","affected_versions":"3.12 and later"}],"env_vars":null,"last_verified":"2026-05-12T17:44:59.489Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the 'overrides' library using pip: 'pip install overrides'.","cause":"The 'overrides' library is not installed in the Python environment.","error":"ModuleNotFoundError: No module named 'overrides'"},{"fix":"Ensure you are using the correct import statement: 'from overrides import override'.","cause":"The 'override' decorator is not available in the 'overrides' module.","error":"ImportError: cannot import name 'override' from 'overrides'"},{"fix":"Use the 'override' decorator with parentheses: '@override()'.","cause":"The 'override' decorator is being used incorrectly, possibly without parentheses.","error":"TypeError: 'override' object is not callable"},{"fix":"Ensure you are using the correct import statement: 'from overrides import EnforceOverrides'.","cause":"The 'EnforceOverrides' metaclass is not available in the 'overrides' module.","error":"AttributeError: module 'overrides' has no attribute 'EnforceOverrides'"},{"fix":"Use the 'override' decorator with the '@' symbol: '@override'.","cause":"The 'override' decorator is used without the '@' symbol.","error":"SyntaxError: unexpected EOF while parsing"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"7.7.0","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"17.9M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.01,"mem_mb":1.4,"disk_size":"18M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1.4,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.6,"disk_size":"19.7M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.6,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.04,"mem_mb":1.6,"disk_size":"20M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.6,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.5,"disk_size":"11.6M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.5,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.05,"mem_mb":1.5,"disk_size":"12M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.5,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.8,"disk_size":"11.3M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.8,"disk_size":"11.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.04,"mem_mb":1.6,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.6,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.3,"disk_size":"17.4M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.3,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.8,"import_time_s":0.02,"mem_mb":1.3,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.3,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}