Skip to content

Commit 237fede

Browse files
committed
Use new infer_variance flag instead of manually specifying type variable
variance
1 parent 087f0be commit 237fede

4 files changed

Lines changed: 41 additions & 41 deletions

File tree

banquo/_banquo_impl.pyi

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from .operators import Bounds, M, M_ge, M_le, M_neg, M_neg_ge
99

1010
class PanicException(Exception): ...
1111

12-
T = TypeVar("T", covariant=True)
12+
_T = TypeVar("_T", infer_variance=True)
1313

1414
class Top(Any): # pyright: ignore[reportAny, reportExplicitAny]
1515
def __le__(self, other: object) -> bool: ...
@@ -27,54 +27,54 @@ class Bottom(Any): # pyright: ignore[reportAny, reportExplicitAny]
2727
def __ge__(self, other: object) -> bool: ...
2828
def __gt__(self, other: object) -> bool: ...
2929

30-
class Trace(Generic[_T_co]):
31-
def __new__(cls, elements: dict[float, _T_co] | Trace[_T_co]) -> Self: ...
32-
def __getitem__(self, value: float) -> _T_co: ...
30+
class Trace(Generic[_T]):
31+
def __new__(cls, elements: dict[float, _T] | Trace[_T]) -> Self: ...
32+
def __getitem__(self, value: float) -> _T: ...
3333
def times(self) -> Iterable[float]: ...
34-
def states(self) -> Iterable[_T_co]: ...
35-
def at_time(self, time: float) -> _T_co | None: ...
34+
def states(self) -> Iterable[_T]: ...
35+
def at_time(self, time: float) -> _T | None: ...
3636

3737
class Predicate(Formula[dict[str, float], float]):
3838
def __new__(cls, coefficients: dict[str, float], constant: float) -> Self: ...
3939
@override
4040
def evaluate(self, trace: Trace[dict[str, float]]) -> Trace[float]: ...
4141

42-
S = TypeVar("S", contravariant=True)
42+
_S = TypeVar("_S", infer_variance=True)
4343

44-
class Not(Formula[S, M_neg]):
45-
def __new__(cls, subformula: Formula[S, M_neg]) -> Self: ...
44+
class Not(Formula[_S, M_neg]):
45+
def __new__(cls, subformula: Formula[_S, M_neg]) -> Self: ...
4646
@override
47-
def evaluate(self, trace: Trace[S]) -> Trace[M_neg]: ...
47+
def evaluate(self, trace: Trace[_S]) -> Trace[M_neg]: ...
4848

49-
class And(Formula[S, M_le]):
50-
def __new__(cls, lhs: Formula[S, M_le], rhs: Formula[S, M_le]) -> Self: ...
49+
class And(Formula[_S, M_le]):
50+
def __new__(cls, lhs: Formula[_S, M_le], rhs: Formula[_S, M_le]) -> Self: ...
5151
@override
52-
def evaluate(self, trace: Trace[S]) -> Trace[M_le]: ...
52+
def evaluate(self, trace: Trace[_S]) -> Trace[M_le]: ...
5353

54-
class Or(Formula[S, M_ge]):
55-
def __new__(cls, lhs: Formula[S, M_ge], rhs: Formula[S, M_ge]) -> Self: ...
54+
class Or(Formula[_S, M_ge]):
55+
def __new__(cls, lhs: Formula[_S, M_ge], rhs: Formula[_S, M_ge]) -> Self: ...
5656
@override
57-
def evaluate(self, trace: Trace[S]) -> Trace[M_ge]: ...
57+
def evaluate(self, trace: Trace[_S]) -> Trace[M_ge]: ...
5858

59-
class Implies(Formula[S, M_neg_ge]):
60-
def __new__(cls, lhs: Formula[S, M_neg_ge], rhs: Formula[S, M_neg_ge]) -> Self: ...
59+
class Implies(Formula[_S, M_neg_ge]):
60+
def __new__(cls, lhs: Formula[_S, M_neg_ge], rhs: Formula[_S, M_neg_ge]) -> Self: ...
6161
@override
62-
def evaluate(self, trace: Trace[S]) -> Trace[M_neg_ge]: ...
62+
def evaluate(self, trace: Trace[_S]) -> Trace[M_neg_ge]: ...
6363

64-
class Next(Formula[S, M]):
65-
def __new__(cls, subformula: Formula[S, M]) -> Self: ...
64+
class Next(Formula[_S, M]):
65+
def __new__(cls, subformula: Formula[_S, M]) -> Self: ...
6666
@override
67-
def evaluate(self, trace: Trace[S]) -> Trace[M]: ...
67+
def evaluate(self, trace: Trace[_S]) -> Trace[M]: ...
6868

69-
class Always(Formula[S, M_le]):
70-
def __new__(cls, bounds: Bounds | None, subformula: Formula[S, M_le]) -> Self: ...
69+
class Always(Formula[_S, M_le]):
70+
def __new__(cls, bounds: Bounds | None, subformula: Formula[_S, M_le]) -> Self: ...
7171
@override
72-
def evaluate(self, trace: Trace[S]) -> Trace[M_le]: ...
72+
def evaluate(self, trace: Trace[_S]) -> Trace[M_le]: ...
7373

74-
class Eventually(Formula[S, M_ge]):
75-
def __new__(cls, bounds: Bounds | None, subformula: Formula[S, M_ge]) -> Self: ...
74+
class Eventually(Formula[_S, M_ge]):
75+
def __new__(cls, bounds: Bounds | None, subformula: Formula[_S, M_ge]) -> Self: ...
7676
@override
77-
def evaluate(self, trace: Trace[S]) -> Trace[M_ge]: ...
77+
def evaluate(self, trace: Trace[_S]) -> Trace[M_ge]: ...
7878

7979
class _StlModule(ModuleType):
8080
class Formula(Formula[dict[str, float], float]): ...

banquo/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from ._banquo_impl import Trace as _Trace
99
from .trace import Trace
1010

11-
S = TypeVar("S", contravariant=True)
12-
M = TypeVar("M", covariant=True)
11+
S = TypeVar("S", infer_variance=True)
12+
M = TypeVar("M", infer_variance=True)
1313

1414

1515
class Formula(Protocol[S, M]):

banquo/operators.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
Bounds: TypeAlias = tuple[float, float]
2424

25-
S = typing.TypeVar("S")
26-
M = typing.TypeVar("M", covariant=True)
27-
M_neg = typing.TypeVar("M_neg", bound=SupportsNeg, covariant=True)
28-
M_le = typing.TypeVar("M_le", bound=SupportsLT, covariant=True)
29-
M_ge = typing.TypeVar("M_ge", bound=SupportsGT, covariant=True)
30-
M_neg_ge = typing.TypeVar("M_neg_ge", bound=SupportsNegGE, covariant=True)
25+
S = TypeVar("S", infer_variance=True)
26+
M = TypeVar("M", infer_variance=True)
27+
M_neg = TypeVar("M_neg", bound=SupportsNeg, infer_variance=True)
28+
M_le = TypeVar("M_le", bound=SupportsLT, infer_variance=True)
29+
M_ge = TypeVar("M_ge", bound=SupportsGT, infer_variance=True)
30+
M_neg_ge = TypeVar("M_neg_ge", bound=SupportsNegGE, infer_variance=True)
3131

3232

3333
class OperatorMixin:
@@ -132,8 +132,8 @@ def __init__(self, subformula: Formula[S, M]):
132132
super().__init__(_Next(_inner_or_wrap(subformula)), "")
133133

134134

135-
S_ = typing.TypeVar("S_")
136-
M_le_ = typing.TypeVar("M_le_", bound=SupportsLT, covariant=True)
135+
S_ = TypeVar("S_", infer_variance=True)
136+
M_le_ = TypeVar("M_le_", bound=SupportsLT, infer_variance=True)
137137

138138

139139
class Always(Operator[S, M_le]):
@@ -173,7 +173,7 @@ def with_bounds(bounds: Bounds, subformula: Formula[S_, M_le_]) -> Always[S_, M_
173173
return Always(_Always(bounds, _inner_or_wrap(subformula)))
174174

175175

176-
M_ge_ = typing.TypeVar("M_ge_", bound=SupportsGT, covariant=True)
176+
M_ge_ = TypeVar("M_ge_", bound=SupportsGT, infer_variance=True)
177177

178178

179179
class Eventually(Operator[S, M_ge]):

banquo/trace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from ._banquo_impl import Trace as _Trace
88

9-
T = TypeVar("T", covariant=True)
10-
U = TypeVar("U", covariant=True)
9+
T = TypeVar("T", infer_variance=True)
10+
U = TypeVar("U", infer_variance=True)
1111

1212

1313
def _iter_eq(lhs: Iterable[object], rhs: Iterable[object]) -> bool:

0 commit comments

Comments
 (0)