Skip to content

Commit

Permalink
Fix Numpy at < 2.0 for Python 3.9 (#357)
Browse files Browse the repository at this point in the history
* Fix Numpy at < 2.0 for Python 3.9

* Ignore type error (fix for Python 3.9)
  • Loading branch information
elenbaasc authored Oct 16, 2024
1 parent dd5c844 commit 8c07174
Show file tree
Hide file tree
Showing 3 changed files with 1,741 additions and 1,093 deletions.
9 changes: 4 additions & 5 deletions opensquirrel/circuit_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,18 @@ def _check_generator_f_args(
"""
for i, par in enumerate(inspect.signature(generator_f).parameters.values()):
try:
expected_type = (
ANNOTATIONS_TO_TYPE_MAP[par.annotation] if isinstance(par.annotation, str) else par.annotation
)
expected_type = ANNOTATIONS_TO_TYPE_MAP[par.annotation] if isinstance(par.annotation, str) \
else par.annotation
except KeyError as e:
msg = "unknown annotation type"
raise TypeError(msg) from e

# fix for python39
try:
is_incorrect_type = not isinstance(args[i], expected_type)
is_incorrect_type = not isinstance(args[i], expected_type) # type: ignore
except TypeError:
# expected type is probably a Union, which works differently in python39
is_incorrect_type = not isinstance(args[i], expected_type.__args__)
is_incorrect_type = not isinstance(args[i], expected_type.__args__) # type: ignore

if is_incorrect_type:
msg = f"wrong argument type for instruction `{attr}`, got {type(args[i])} but expected {expected_type}"
Expand Down
Loading

0 comments on commit 8c07174

Please sign in to comment.