Skip to content

Commit

Permalink
update type-check logic for python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Aug 2, 2024
1 parent 6f030cc commit 6e52078
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lenskit/lenskit/pipeline/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def is_compatible_type(typ: type, *targets: type) -> bool:
if isinstance(target, (GenericAlias, _GenericAlias)):
tcls = get_origin(target)
# if we're matching a raw type against a generic, just check the origin
if isinstance(typ, type):
if issubclass(typ, tcls): # type: ignore
return True
elif isinstance(typ, GenericAlias):
if isinstance(typ, GenericAlias):
warnings.warn(f"cannot type-check generic type {typ}", TypecheckWarning)
cls = get_origin(typ)
if issubclass(cls, tcls):
if issubclass(cls, tcls): # type: ignore
return True
elif isinstance(typ, type):
print(typ, type(typ))
if issubclass(typ, tcls): # type: ignore
return True
elif typ == int and issubclass(target, (float, complex)): # noqa: E721
return True
Expand Down

0 comments on commit 6e52078

Please sign in to comment.