Skip to content

Commit

Permalink
refactor the version checking outside function definition
Browse files Browse the repository at this point in the history
  • Loading branch information
yzjin authored and pabloferz committed Jul 24, 2024
1 parent 101d72a commit 6e8b932
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pysages/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@ def has_method(fn, T, index):
_typing = import_module("plum" if _plum_version_tuple < (2, 2, 1) else "typing")
_util = _typing.type if _plum_version_tuple < (2, 2, 1) else _typing

if _plum_version_tuple < (2, 3, 0):
def _signature_types(sig):
return sig.types
else:
def _signature_types(sig):
return sig.signature.types

def dispatch_table(dispatch):
return dispatch.functions

def has_method(fn, T, index):
types_at_index = set()
for sig in fn.methods:
if _plum_version_tuple < (2, 3, 0):
typ = sig.types[index]
else:
typ = sig.signature.types[index]
typ = _signature_types(sig)[index]
if _util.get_origin(typ) is _typing.Union:
types_at_index.update(_util.get_args(typ))
else:
Expand Down

0 comments on commit 6e8b932

Please sign in to comment.