Skip to content

Commit fd32016

Browse files
committed
Fix 3.10 incompatibility
1 parent e97ee9d commit fd32016

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

backend/spellbook/variants/minimal_set_of_multisets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterable, TypeVar, Generic, Self
1+
from typing import Iterable, TypeVar, Generic
22
from .multiset import FrozenMultiset
33

44
_T = TypeVar('_T')
@@ -83,14 +83,14 @@ def __eq__(self, other):
8383
return self.__sets == other.__sets
8484
return False
8585

86-
def __copy__(self) -> Self:
86+
def __copy__(self):
8787
return self.__class__(_internal=self.__sets.copy())
8888

89-
def copy(self) -> Self:
89+
def copy(self):
9090
"Returns a shallow copy of the collection."
9191
return self.__copy__()
9292

93-
def __or__(self, other: Self) -> Self:
93+
def __or__(self, other: 'MinimalSetOfMultisets[_T]'): # TODO: replace with Self from typing with pypy 3.11
9494
result = self.copy()
9595
result.extend(other)
9696
return result

backend/spellbook/variants/multiset.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import MutableMapping, Self, Generic, TypeVar, Hashable, Mapping as MappingType, Union, Optional, Iterable as IterableType, \
1+
from typing import MutableMapping, Generic, TypeVar, Hashable, Mapping as MappingType, Union, Optional, Iterable as IterableType, \
22
ItemsView, KeysView, ValuesView
33
from collections import Counter
44
from collections.abc import Mapping
@@ -51,19 +51,19 @@ def __len__(self) -> int:
5151
def isdisjoint(self, other: 'BaseMultiset[_T]') -> bool:
5252
return self._elements.keys().isdisjoint(other._elements.keys())
5353

54-
def difference(self, other: 'BaseMultiset[_T]') -> Self:
54+
def difference(self, other: 'BaseMultiset[_T]'):
5555
return self.__class__(_internal=self._elements - other._elements)
5656

57-
def union(self, other: 'BaseMultiset[_T]') -> Self:
57+
def union(self, other: 'BaseMultiset[_T]'):
5858
return self.__class__(_internal=self._elements | other._elements)
5959

60-
def combine(self, other: 'BaseMultiset[_T]') -> Self:
60+
def combine(self, other: 'BaseMultiset[_T]'):
6161
return self.__class__(_internal=self._elements + other._elements)
6262

63-
def intersection(self, other: 'BaseMultiset[_T]') -> Self:
63+
def intersection(self, other: 'BaseMultiset[_T]'):
6464
return self.__class__(_internal=self._elements & other._elements)
6565

66-
def times(self, factor: int) -> Self:
66+
def times(self, factor: int):
6767
if factor == 0:
6868
return self.__class__()
6969
if factor < 0:
@@ -102,7 +102,7 @@ def __eq__(self, other: object) -> bool:
102102
def get(self, element: _T, default: int) -> int:
103103
return self._elements.get(element, default)
104104

105-
def copy(self) -> Self:
105+
def copy(self):
106106
return self.__class__(_internal=self._elements.copy())
107107

108108
__copy__ = copy
@@ -128,22 +128,22 @@ def __ge__(self, other: 'BaseMultiset[_T]') -> bool:
128128
def __gt__(self, other: 'BaseMultiset[_T]') -> bool:
129129
return self._total > other._total and self.issuperset(other)
130130

131-
def __add__(self, other: 'BaseMultiset[_T]') -> Self:
131+
def __add__(self, other: 'BaseMultiset[_T]'):
132132
return self.combine(other)
133133

134-
def __sub__(self, other: 'BaseMultiset[_T]') -> Self:
134+
def __sub__(self, other: 'BaseMultiset[_T]'):
135135
return self.difference(other)
136136

137-
def __mul__(self, factor: int) -> Self:
137+
def __mul__(self, factor: int):
138138
return self.times(factor)
139139

140-
def __rmul__(self, factor: int) -> Self:
140+
def __rmul__(self, factor: int):
141141
return self.times(factor)
142142

143-
def __or__(self, other: 'BaseMultiset[_T]') -> Self:
143+
def __or__(self, other: 'BaseMultiset[_T]'):
144144
return self.union(other)
145145

146-
def __and__(self, other: 'BaseMultiset[_T]') -> Self:
146+
def __and__(self, other: 'BaseMultiset[_T]'):
147147
return self.intersection(other)
148148

149149
def __floordiv__(self, other: 'BaseMultiset[_T]') -> int:

backend/spellbook/variants/variant_set.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterable, Callable, Self
1+
from typing import Iterable, Callable
22
from itertools import product, chain
33
from functools import reduce
44
from dataclasses import dataclass, replace
@@ -61,7 +61,7 @@ def entry_to_ingredients(cls, entry: Entry) -> tuple[FrozenMultiset[cardid], Fro
6161
def entries(self) -> Iterable[Entry]:
6262
return self.sets
6363

64-
def filter(self, entry: Entry) -> Self:
64+
def filter(self, entry: Entry):
6565
return self.__class__(parameters=replace(self.parameters, filter=entry), _internal=self.sets.subtree(entry))
6666

6767
def __str__(self) -> str:
@@ -70,11 +70,11 @@ def __str__(self) -> str:
7070
def __len__(self) -> int:
7171
return len(self.sets)
7272

73-
def __or__(self, other: Self) -> Self:
73+
def __or__(self, other: 'VariantSet'): # TODO: replace with Self from typing with pypy 3.11
7474
assert self.parameters == other.parameters, "Cannot union VariantSets with different parameters"
7575
return self.__class__(parameters=self.parameters, _internal=self.sets | other.sets)
7676

77-
def __and__(self, other: Self):
77+
def __and__(self, other: 'VariantSet'): # TODO: replace with Self from typing with pypy 3.11
7878
assert self.parameters == other.parameters, "Cannot intersect VariantSets with different parameters"
7979
result = MinimalSetOfMultisets[int]()
8080
for left_entry, right_entry in product(self.entries(), other.entries()):
@@ -84,7 +84,7 @@ def __and__(self, other: Self):
8484
result.add(entry)
8585
return self.__class__(parameters=self.parameters, _internal=result)
8686

87-
def __add__(self, other: Self):
87+
def __add__(self, other: 'VariantSet'): # TODO: replace with Self from typing with pypy 3.11
8888
assert self.parameters == other.parameters, "Cannot sum VariantSets with different parameters"
8989
result = MinimalSetOfMultisets[int]()
9090
for left_key, right_key in product(self.entries(), other.entries()):
@@ -98,25 +98,25 @@ def variants(self) -> list[tuple[FrozenMultiset[cardid], FrozenMultiset[template
9898
return [self.entry_to_ingredients(e) for e in self.entries()]
9999

100100
@classmethod
101-
def or_sets(cls, sets: list[Self], parameters: VariantSetParameters | None = None) -> Self:
101+
def or_sets(cls, sets: list['VariantSet'], parameters: VariantSetParameters | None = None): # TODO: replace with Self from typing with pypy 3.11
102102
return cls.aggregate_sets(sets, strategy=lambda x, y: x | y, parameters=parameters)
103103

104104
@classmethod
105-
def and_sets(cls, sets: list[Self], parameters: VariantSetParameters | None = None) -> Self:
105+
def and_sets(cls, sets: list['VariantSet'], parameters: VariantSetParameters | None = None): # TODO: replace with Self from typing with pypy 3.11
106106
return cls.aggregate_sets(sets, strategy=lambda x, y: x & y, parameters=parameters)
107107

108108
@classmethod
109-
def sum_sets(cls, sets: list[Self], parameters: VariantSetParameters | None = None) -> Self:
109+
def sum_sets(cls, sets: list['VariantSet'], parameters: VariantSetParameters | None = None): # TODO: replace with Self from typing with pypy 3.11
110110
return cls.aggregate_sets(sets, strategy=lambda x, y: x + y, parameters=parameters)
111111

112112
@classmethod
113-
def aggregate_sets(cls, sets: list[Self], strategy: Callable[[Self, Self], Self], parameters: VariantSetParameters | None = None) -> Self:
113+
def aggregate_sets(cls, sets: list['VariantSet'], strategy: Callable[['VariantSet', 'VariantSet'], 'VariantSet'], parameters: VariantSetParameters | None = None): # TODO: replace with Self from typing with pypy 3.11
114114
match len(sets):
115115
case 0: return cls(parameters=parameters)
116116
case _: return reduce(strategy, sets)
117117

118118
@classmethod
119-
def product_sets(cls, sets: list[Self], parameters: VariantSetParameters | None = None) -> Self:
119+
def product_sets(cls, sets: list['VariantSet'], parameters: VariantSetParameters | None = None): # TODO: replace with Self from typing with pypy 3.11
120120
parameters = parameters if parameters is not None else VariantSetParameters()
121121
if parameters.allow_multiple_copies:
122122
return cls.sum_sets(sets, parameters=parameters)

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ You need:
2828
- `flake8` for linting the code, which is mandatory for contributing otherwise the CI will fail
2929
- [Optional] VS Code with the Python extension, for development and debugging exploiting the `launch.json` configuration
3030
- `pytest` to run the unit tests in VS Code
31+
- [Optional] PyPy 3.10 or later for running long tasks faster
32+
- Remember to install the dependencies using `pypy -m pip install -r requirements.txt` in the backend folder

0 commit comments

Comments
 (0)