Skip to content

Commit

Permalink
BUG: Avoid isinstance on subscripted generics < 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-Stevens-Haas committed Jul 25, 2023
1 parent 95e178a commit c164bad
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions pysindy/pysindy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import warnings
from itertools import product
from typing import Collection
Expand Down Expand Up @@ -778,14 +779,32 @@ def _check_multiple_trajectories(x, x_dot, u) -> bool:
"""
SequenceOrNone = Union[Sequence, None]
mixed_trajectories = (
isinstance(x, Sequence)
and (not isinstance(x_dot, SequenceOrNone) or not isinstance(u, SequenceOrNone))
or isinstance(x_dot, Sequence)
and not isinstance(x, Sequence)
or isinstance(u, Sequence)
and not isinstance(x, Sequence)
)
if sys.version_info.minor < 10:
mixed_trajectories = (
isinstance(x, Sequence)
and (
not isinstance(x_dot, Sequence)
and x_dot is not None
or not isinstance(u, Sequence)
and u is not None
)
or isinstance(x_dot, Sequence)
and not isinstance(x, Sequence)
or isinstance(u, Sequence)
and not isinstance(x, Sequence)
)
else:
mixed_trajectories = (
isinstance(x, Sequence)
and (
not isinstance(x_dot, SequenceOrNone)
or not isinstance(u, SequenceOrNone)
)
or isinstance(x_dot, Sequence)
and not isinstance(x, Sequence)
or isinstance(u, Sequence)
and not isinstance(x, Sequence)
)
if mixed_trajectories:
raise TypeError(
"If x, x_dot, or u are a Sequence of trajectories, each must be a Sequence"
Expand Down

0 comments on commit c164bad

Please sign in to comment.