Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorpela committed Oct 17, 2022
1 parent a548f8b commit 19b9269
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
46 changes: 34 additions & 12 deletions overrides/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ def overrides(
The decorator code is executed while loading class. Using this method
should have minimal runtime performance implications.
This is based on my idea about how to do this and fwc:s highly improved
algorithm for the implementation fwc:s
algorithm : http://stackoverflow.com/a/14631397/308189
my answer : http://stackoverflow.com/a/8313042/308189
How to use:
from overrides import overrides
Expand All @@ -74,7 +69,7 @@ def method(self):
class SubClass(SuperClass):
@override
@overrides
def method(self):
return 1
Expand Down Expand Up @@ -120,15 +115,42 @@ def override(
check_signature: bool = True,
check_at_runtime: bool = False,
) -> Union[_DecoratorMethod, _WrappedMethod]:
return overrides(
method, check_signature=check_signature, check_at_runtime=check_at_runtime
)
"""Decorator to indicate that the decorated method overrides a method in
superclass.
The decorator code is executed while loading class. Using this method
should have minimal runtime performance implications.
How to use:
from overrides import override
class SuperClass(object):
def method(self):
return 2
class SubClass(SuperClass):
@override
def method(self):
return 1
:param check_signature: Whether or not to check the signature of the overridden method.
:param check_at_runtime: Whether or not to check the overridden method at runtime.
:raises AssertionError: if no match in super classes for the method name
:return: method with possibly added (if the method doesn't have one)
docstring from super class
"""
if method is not None:
return _overrides(method, check_signature, check_at_runtime)
else:
return functools.partial(
overrides,
check_signature=check_signature,
check_at_runtime=check_at_runtime,
)


def _overrides(
method: _WrappedMethod,
check_signature: bool,
check_at_runtime: bool,
method: _WrappedMethod, check_signature: bool, check_at_runtime: bool,
) -> _WrappedMethod:
setattr(method, "__override__", True)
global_vars = getattr(method, "__globals__", None)
Expand Down
8 changes: 2 additions & 6 deletions overrides/typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ def _is_origin_subtype(left: OriginType, right: OriginType) -> bool:


NormalizedTypeArgs = typing.Union[
typing.Tuple[typing.Any, ...],
typing.FrozenSet[NormalizedType],
NormalizedType,
typing.Tuple[typing.Any, ...], typing.FrozenSet[NormalizedType], NormalizedType,
]


Expand Down Expand Up @@ -418,9 +416,7 @@ def _is_normal_subtype(


def issubtype(
left: Type,
right: Type,
forward_refs: typing.Optional[dict] = None,
left: Type, right: Type, forward_refs: typing.Optional[dict] = None,
) -> typing.Optional[bool]:
"""Check that the left argument is a subtype of the right.
For unions, check if the type arguments of the left is a subset of the right.
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
author_email=address,
url="https://github.com/mkorpela/overrides",
packages=find_packages(),
package_data={
"overrides": ["*.pyi", "py.typed"],
},
package_data={"overrides": ["*.pyi", "py.typed"],},
include_package_data=True,
install_requires=['typing;python_version<"3.5"'],
python_requires=">=3.6",
Expand Down

0 comments on commit 19b9269

Please sign in to comment.