Skip to content

Commit

Permalink
TypeVar can not be used in issubclass
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Nov 29, 2023
1 parent 3f44620 commit 33ca797
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions spinn_utilities/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def __is_similar_type(self, method_type, super_type, arg):
return True

# If one is generic they must be the exact same object
if (isinstance(method_type, _BaseGenericAlias) or
isinstance(super_type, _BaseGenericAlias)):
if (isinstance(method_type, (TypeVar, _BaseGenericAlias)) or
isinstance(super_type, (TypeVar, _BaseGenericAlias))):
if arg == "return":
if self._return_narrowing:
return True
Expand Down Expand Up @@ -172,8 +172,11 @@ def __is_similar_type(self, method_type, super_type, arg):
f"Method {self._override_name} has {arg} typed as "
f"{method_type} while super is typed as {super_type}. "
f"For None imported types they must be exactly the same")

return issubclass(method_type, super_type)
try:
return issubclass(method_type, super_type)
except TypeError as ex:
raise TypeError (f"Unable to subtype {super_type}"
f" {type(super_type)} for {arg}") from ex

def __verify_method_types(self, method: Method):
try:
Expand Down

0 comments on commit 33ca797

Please sign in to comment.