diff --git a/overrides/__init__.py b/overrides/__init__.py index 1986079..fde8166 100644 --- a/overrides/__init__.py +++ b/overrides/__init__.py @@ -1,5 +1,9 @@ from overrides.enforce import EnforceOverrides -from overrides.final import final +import sys +if sys.version_info < (3, 11): + from overrides.final import final +else: + from typing import final from overrides.overrides import __VERSION__, overrides __all__ = [ diff --git a/overrides/enforce.py b/overrides/enforce.py index 56a91cd..8901c3d 100644 --- a/overrides/enforce.py +++ b/overrides/enforce.py @@ -38,8 +38,8 @@ def _check_if_overrides_without_overrides_decorator(name, value, bases): def _check_if_overrides_final_method(name, bases): for base in bases: base_class_method = getattr(base, name, False) - # `__finalized__` is added by `@final` decorator - if getattr(base_class_method, "__finalized__", False): + # `__final__` is added by `@final` decorator + if getattr(base_class_method, "__final__", False): raise TypeError( f"Method {name} is finalized in {base}, it cannot be overridden" ) diff --git a/overrides/final.py b/overrides/final.py index a92e60c..14dde3c 100644 --- a/overrides/final.py +++ b/overrides/final.py @@ -16,9 +16,6 @@ from types import FunctionType from typing import Callable, TypeVar, Union -__VERSION__ = "0.1" - - _WrappedMethod = TypeVar("_WrappedMethod", bound=Union[FunctionType, Callable]) @@ -44,5 +41,5 @@ def method(self): #causes an error :raises AssertionError: if there exists a match in sub classes for the method name :return: method """ - setattr(method, "__finalized__", True) + setattr(method, "__final__", True) return method diff --git a/overrides/overrides.py b/overrides/overrides.py index 8573ecb..a3c475b 100644 --- a/overrides/overrides.py +++ b/overrides/overrides.py @@ -122,10 +122,8 @@ def _validate_method(method, super_class, check_signature): is_static = isinstance( inspect.getattr_static(super_class, method.__name__), staticmethod ) - if hasattr(super_method, "__finalized__"): - finalized = getattr(super_method, "__finalized__") - if finalized: - raise TypeError(f"{method.__name__}: is finalized in {super_class}") + if getattr(super_method, "__final__", False): + raise TypeError(f"{method.__name__}: is finalized in {super_class}") if not method.__doc__: method.__doc__ = super_method.__doc__ if ( diff --git a/setup.py b/setup.py index 8bc6bcc..f66529d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from os.path import abspath, join, dirname name = "Mikko Korpela" -# I might be just a little bit too much afraid of those bots.. +# I might be just a bit too much afraid of those bots. address = name.lower().replace(" ", ".") + chr(64) + "gmail.com" desc = "A decorator to automatically detect mismatch when overriding a method."