Skip to content

Commit a672add

Browse files
committed
Fixed type compatibility for python version 3.9
1 parent 8fec030 commit a672add

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

portion/dict.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Mapping,
1010
MutableMapping,
1111
)
12-
from typing import Protocol, cast, overload, override
12+
from typing import Protocol, TypeVar, cast, overload, override
1313

1414
from sortedcontainers import SortedDict
1515
from sortedcontainers.sorteddict import ItemsView, KeysView, ValuesView
@@ -23,11 +23,14 @@ def _sortkey(i: tuple[Interval, object]) -> tuple[object, bool]:
2323
return (i[0].lower, i[0].left is Bound.OPEN)
2424

2525

26-
class HowToCombineSingle[V](Protocol):
26+
V = TypeVar("V")
27+
28+
29+
class HowToCombineSingle(Protocol):
2730
def __call__(self, x: V, y: V) -> V: ...
2831

2932

30-
class HowToCombineWithInterval[V](Protocol):
33+
class HowToCombineWithInterval(Protocol):
3134
def __call__(self, x: V, y: V, i: Interval) -> V: ...
3235

3336

@@ -302,10 +305,8 @@ def update(
302305
def combine(
303306
self,
304307
other: "IntervalDict[V]",
305-
how: HowToCombineSingle[V]
306-
| HowToCombineWithInterval[
307-
V
308-
], # Callable[[V, V], V] | Callable[[V, V, Interval], V],
308+
how: HowToCombineSingle
309+
| HowToCombineWithInterval, # Callable[[V, V], V] | Callable[[V, V, Interval], V],
309310
*,
310311
missing: V = ...,
311312
pass_interval: bool = False,
@@ -335,12 +336,12 @@ def combine(
335336
new_items = []
336337

337338
if not pass_interval:
338-
how = cast(HowToCombineSingle[V], how)
339+
how = cast(HowToCombineSingle, how)
339340

340341
def _how(x: V, y: V, i: Interval) -> V:
341342
return how(x, y)
342343
else:
343-
how = cast(HowToCombineWithInterval[V], how)
344+
how = cast(HowToCombineWithInterval, how)
344345
_how = how
345346
dom1, dom2 = self.domain(), other.domain()
346347

0 commit comments

Comments
 (0)