Skip to content

Commit e931639

Browse files
Action renovation x1
1 parent fbbceca commit e931639

File tree

1 file changed

+79
-81
lines changed

1 file changed

+79
-81
lines changed

libsemigroups_pybind11/action.py

Lines changed: 79 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,155 +14,153 @@
1414
the Action class from libsemigroups.
1515
"""
1616

17-
# TODO add _ as prefix of everything imported
18-
1917
from typing import Any, Union, Iterator
20-
from typing_extensions import Self
18+
from typing_extensions import Self as _Self
2119

2220
from _libsemigroups_pybind11 import (
23-
RightActionBMat8BMat8 as _RightActionBMat8BMat8,
21+
BMat8 as _BMat8,
2422
LeftActionBMat8BMat8 as _LeftActionBMat8BMat8,
25-
RightActionPPerm1List as _RightActionPPerm1List,
26-
RightActionPPerm2List as _RightActionPPerm2List,
27-
RightActionPPerm4List as _RightActionPPerm4List,
28-
RightActionPPerm1PPerm1 as _RightActionPPerm1PPerm1,
2923
LeftActionPPerm1List as _LeftActionPPerm1List,
24+
LeftActionPPerm1PPerm1 as _LeftActionPPerm1PPerm1,
3025
LeftActionPPerm2List as _LeftActionPPerm2List,
3126
LeftActionPPerm4List as _LeftActionPPerm4List,
32-
LeftActionPPerm1PPerm1 as _LeftActionPPerm1PPerm1,
33-
RightActionTransf1List as _RightActionTransf1List,
34-
RightActionTransf2List as _RightActionTransf2List,
35-
RightActionTransf4List as _RightActionTransf4List,
3627
LeftActionTransf1List as _LeftActionTransf1List,
3728
LeftActionTransf2List as _LeftActionTransf2List,
3829
LeftActionTransf4List as _LeftActionTransf4List,
3930
PPerm1 as _PPerm1,
4031
PPerm2 as _PPerm2,
4132
PPerm4 as _PPerm4,
33+
RightActionBMat8BMat8 as _RightActionBMat8BMat8,
34+
RightActionPPerm1List as _RightActionPPerm1List,
35+
RightActionPPerm1PPerm1 as _RightActionPPerm1PPerm1,
36+
RightActionPPerm2List as _RightActionPPerm2List,
37+
RightActionPPerm4List as _RightActionPPerm4List,
38+
RightActionTransf1List as _RightActionTransf1List,
39+
RightActionTransf2List as _RightActionTransf2List,
40+
RightActionTransf4List as _RightActionTransf4List,
4241
Transf1 as _Transf1,
4342
Transf2 as _Transf2,
4443
Transf4 as _Transf4,
44+
UNDEFINED as _UNDEFINED,
45+
side,
4546
)
4647

47-
from _libsemigroups_pybind11 import BMat8, side, UNDEFINED
48-
49-
from .adapters import ImageRightAction, ImageLeftAction
50-
from .transf import PPerm, Transf
48+
from .adapters import (
49+
ImageRightAction as _ImageRightAction,
50+
ImageLeftAction as _ImageLeftAction,
51+
)
52+
from .transf import PPerm as _PPerm, Transf as _Transf
5153

52-
from .detail.cxx_wrapper import to_cxx, to_py, CxxWrapper as _CxxWrapper
54+
from .detail.cxx_wrapper import (
55+
to_cxx as _to_cxx,
56+
to_py as _to_py,
57+
CxxWrapper as _CxxWrapper,
58+
)
5359

5460

5561
# TODO doc
56-
class Action(
57-
_CxxWrapper
58-
): # pylint: disable=invalid-name, too-many-instance-attributes, no-member
62+
class Action(_CxxWrapper):
5963
"""
6064
The documentation for this class is taken from RightActionPPerm1List in
6165
src/action.cpp!
6266
"""
6367

6468
_py_template_params_to_cxx_type = {
65-
(BMat8, BMat8, ImageRightAction, side.right): _RightActionBMat8BMat8,
66-
(BMat8, BMat8, ImageLeftAction, side.left): _LeftActionBMat8BMat8,
67-
(PPerm, PPerm, ImageRightAction, side.right): {
69+
(_BMat8, _BMat8, _ImageRightAction, side.right): _RightActionBMat8BMat8,
70+
(_BMat8, _BMat8, _ImageLeftAction, side.left): _LeftActionBMat8BMat8,
71+
(_PPerm, _PPerm, _ImageRightAction, side.right): {
6872
(
6973
_PPerm1,
7074
_PPerm1,
71-
ImageRightAction,
75+
_ImageRightAction,
7276
side.right,
7377
): _RightActionPPerm1PPerm1,
7478
},
75-
(PPerm, PPerm, ImageLeftAction, side.left): {
79+
(_PPerm, _PPerm, _ImageLeftAction, side.left): {
7680
(
7781
_PPerm1,
7882
_PPerm1,
79-
ImageLeftAction,
83+
_ImageLeftAction,
8084
side.left,
8185
): _LeftActionPPerm1PPerm1,
8286
},
83-
(PPerm, list, ImageRightAction, side.right): {
87+
(_PPerm, list, _ImageRightAction, side.right): {
8488
(
8589
_PPerm1,
8690
list,
87-
ImageRightAction,
91+
_ImageRightAction,
8892
side.right,
8993
): _RightActionPPerm1List,
9094
(
9195
_PPerm2,
9296
list,
93-
ImageRightAction,
97+
_ImageRightAction,
9498
side.right,
9599
): _RightActionPPerm2List,
96100
(
97101
_PPerm4,
98102
list,
99-
ImageRightAction,
103+
_ImageRightAction,
100104
side.right,
101105
): _RightActionPPerm4List,
102106
},
103-
(PPerm, list, ImageLeftAction, side.left): {
107+
(_PPerm, list, _ImageLeftAction, side.left): {
104108
(
105109
_PPerm1,
106110
list,
107-
ImageLeftAction,
111+
_ImageLeftAction,
108112
side.left,
109113
): _LeftActionPPerm1List,
110-
(
111-
_PPerm1,
112-
list,
113-
ImageLeftAction,
114-
side.right, # TODO left?
115-
): _LeftActionPPerm1List,
116114
(
117115
_PPerm2,
118116
list,
119-
ImageLeftAction,
120-
side.right, # TODO left?
117+
_ImageLeftAction,
118+
side.left,
121119
): _LeftActionPPerm2List,
122120
(
123121
_PPerm4,
124122
list,
125-
ImageLeftAction,
126-
side.right, # TODO left?
123+
_ImageLeftAction,
124+
side.left,
127125
): _LeftActionPPerm4List,
128126
},
129-
(Transf, list, ImageRightAction, side.right): {
127+
(_Transf, list, _ImageRightAction, side.right): {
130128
(
131129
_Transf1,
132130
list,
133-
ImageRightAction,
131+
_ImageRightAction,
134132
side.right,
135133
): _RightActionTransf1List,
136134
(
137135
_Transf2,
138136
list,
139-
ImageRightAction,
137+
_ImageRightAction,
140138
side.right,
141139
): _RightActionTransf2List,
142140
(
143141
_Transf4,
144142
list,
145-
ImageRightAction,
143+
_ImageRightAction,
146144
side.right,
147145
): _RightActionTransf4List,
148146
},
149-
(Transf, list, ImageLeftAction, side.left): {
147+
(_Transf, list, _ImageLeftAction, side.left): {
150148
(
151149
_Transf1,
152150
list,
153-
ImageLeftAction,
151+
_ImageLeftAction,
154152
side.left,
155153
): _LeftActionTransf1List,
156154
(
157155
_Transf2,
158156
list,
159-
ImageLeftAction,
157+
_ImageLeftAction,
160158
side.left,
161159
): _LeftActionTransf2List,
162160
(
163161
_Transf4,
164162
list,
165-
ImageLeftAction,
163+
_ImageLeftAction,
166164
side.left,
167165
): _LeftActionTransf4List,
168166
},
@@ -171,7 +169,7 @@ class Action(
171169
# TODO _cxx_type_to_py_template_params??
172170
# TODO _all_wrapped_cxx_types
173171

174-
def __init__(self: Self, **kwargs):
172+
def __init__(self: _Self, **kwargs):
175173
super().__init__(
176174
required_kwargs=("Element", "Point", "Func", "Side"), **kwargs
177175
)
@@ -181,11 +179,11 @@ def __init__(self: Self, **kwargs):
181179
self.Side = kwargs["Side"]
182180
self.init()
183181

184-
def __getattr__(self: Self, meth_name: str) -> Any:
182+
def __getattr__(self: _Self, meth_name: str) -> Any:
185183
self._init_cxx_obj()
186184
return super().__getattr__(meth_name)
187185

188-
def _init_cxx_obj(self: Self) -> None:
186+
def _init_cxx_obj(self: _Self) -> None:
189187
# pylint: disable=attribute-defined-outside-init
190188
if self._cxx_obj is not None:
191189
return
@@ -208,13 +206,13 @@ def _init_cxx_obj(self: Self) -> None:
208206
self._cxx_obj = cxx_obj_t()
209207

210208
for x in self._generators:
211-
self._cxx_obj.add_generator(to_cxx(x))
209+
self._cxx_obj.add_generator(_to_cxx(x))
212210
for x in self._seeds:
213-
self._cxx_obj.add_seed(to_cxx(x))
211+
self._cxx_obj.add_seed(_to_cxx(x))
214212
self._cxx_obj.cache_scc_multipliers(self._cache_scc_multipliers)
215213
self._cxx_obj.reserve(self._reserve)
216214

217-
def __repr__(self: Self) -> str:
215+
def __repr__(self: _Self) -> str:
218216
result = super().__repr__()
219217
if result:
220218
return result
@@ -223,20 +221,20 @@ def __repr__(self: Self) -> str:
223221
f"{len(self._seeds)} points>"
224222
)
225223

226-
def __getitem__(self: Self, pos: int) -> Any:
224+
def __getitem__(self: _Self, pos: int) -> Any:
227225
self._init_cxx_obj()
228-
return to_py(self.Point, self._cxx_obj[pos])
226+
return _to_py(self.Point, self._cxx_obj[pos])
229227

230-
def __len__(self: Self):
228+
def __len__(self: _Self):
231229
self._init_cxx_obj()
232230
return getattr(self._cxx_obj, "size")()
233231

234232
# TODO type annotations
235-
def index(self: Self, x) -> int:
233+
def index(self: _Self, x) -> int:
236234
self._init_cxx_obj()
237-
return getattr(self._cxx_obj, "position")(to_cxx(x))
235+
return getattr(self._cxx_obj, "position")(_to_cxx(x))
238236

239-
def add_generator(self: Self, x: Any) -> Self:
237+
def add_generator(self: _Self, x: Any) -> _Self:
240238
if not isinstance(x, self.Element):
241239
raise ValueError(
242240
"the argument (generator) has incorrect type, expected "
@@ -253,26 +251,26 @@ def add_generator(self: Self, x: Any) -> Self:
253251
)
254252

255253
if self._cxx_obj is not None:
256-
self._cxx_obj.add_generator(to_cxx(x))
254+
self._cxx_obj.add_generator(_to_cxx(x))
257255
else:
258256
self._generators.append(x)
259257
return self
260258

261-
def add_seed(self: Self, x: Any) -> Self:
259+
def add_seed(self: _Self, x: Any) -> _Self:
262260
if not isinstance(x, self.Point):
263261
raise ValueError(
264262
"the argument (seed) has incorrect type, expected "
265263
f"{self.Element} but found {type(x)}"
266264
)
267265
if self._cxx_obj is not None:
268-
self._cxx_obj.add_seed(to_cxx(x))
266+
self._cxx_obj.add_seed(_to_cxx(x))
269267
else:
270268
# TODO check compatibility of x with things already in _seeds,
271269
# i.e. degree. Not currently sure how to do this
272270
self._seeds.append(x)
273271
return self
274272

275-
def cache_scc_multipliers(self: Self, *args) -> Union[Self, bool]:
273+
def cache_scc_multipliers(self: _Self, *args) -> Union[_Self, bool]:
276274
# pylint: disable=attribute-defined-outside-init
277275
if self._cxx_obj is not None:
278276
return self._cxx_obj.cache_scc_multipliers(*args)
@@ -285,48 +283,48 @@ def cache_scc_multipliers(self: Self, *args) -> Union[Self, bool]:
285283
f"expected 0 arguments or 1 argument (a bool), found {len(args)} arguments"
286284
)
287285

288-
def current_size(self: Self) -> int:
286+
def current_size(self: _Self) -> int:
289287
if self._cxx_obj is not None:
290288
return self._cxx_obj.current_size()
291289
return len(self._seeds)
292290

293-
def empty(self: Self) -> bool:
291+
def empty(self: _Self) -> bool:
294292
return self.current_size() != 0
295293

296-
def init(self: Self) -> Self:
294+
def init(self: _Self) -> _Self:
297295
self._generators = []
298296
self._seeds = []
299297
self._cache_scc_multipliers = False
300298
self._reserve = 0
301299
self._cxx_obj = None
302300
return self
303301

304-
def multiplier_from_scc_root(self: Self, pos: int) -> Any:
302+
def multiplier_from_scc_root(self: _Self, pos: int) -> Any:
305303
self._init_cxx_obj()
306-
return to_py(self.Element, self._cxx_obj.multiplier_from_scc_root(pos))
304+
return _to_py(self.Element, self._cxx_obj.multiplier_from_scc_root(pos))
307305

308-
def multiplier_to_scc_root(self: Self, pos: int) -> Any:
306+
def multiplier_to_scc_root(self: _Self, pos: int) -> Any:
309307
self._init_cxx_obj()
310-
return to_py(self.Element, self._cxx_obj.multiplier_to_scc_root(pos))
308+
return _to_py(self.Element, self._cxx_obj.multiplier_to_scc_root(pos))
311309

312-
def number_of_generators(self: Self) -> int:
310+
def number_of_generators(self: _Self) -> int:
313311
if self._cxx_obj is None:
314312
return len(self._generators)
315313

316314
return self._cxx_obj.number_of_generators()
317315

318-
def __contains__(self: Self, pt: Any) -> bool:
319-
return self.index(pt) != UNDEFINED
316+
def __contains__(self: _Self, pt: Any) -> bool:
317+
return self.index(pt) != _UNDEFINED
320318

321-
def reserve(self: Self, val: int) -> Self:
319+
def reserve(self: _Self, val: int) -> _Self:
322320
# pylint: disable=attribute-defined-outside-init
323321
if self._cxx_obj is None:
324322
self._reserve = val
325323
else:
326324
self._cxx_obj.reserve(val)
327325
return self
328326

329-
def root_of_scc(self: Self, x: Any) -> Any:
327+
def root_of_scc(self: _Self, x: Any) -> Any:
330328
if not isinstance(x, self.Element) and not isinstance(x, int):
331329
raise ValueError(
332330
"the 1st argument has incorrect type expected "
@@ -335,7 +333,7 @@ def root_of_scc(self: Self, x: Any) -> Any:
335333

336334
self.run()
337335
if isinstance(x, self.Element):
338-
x = to_cxx(x)
336+
x = _to_cxx(x)
339337
return self._cxx_obj.root_of_scc(x)
340338

341339

@@ -344,7 +342,7 @@ def root_of_scc(self: Self, x: Any) -> Any:
344342

345343

346344
def RightAction(
347-
Func=ImageRightAction, **kwargs
345+
Func=_ImageRightAction, **kwargs
348346
): # pylint: disable=invalid-name
349347
"""
350348
Construct a right :any:`RightActionPPerm1List` instance.
@@ -364,7 +362,7 @@ def RightAction(
364362
)
365363

366364

367-
def LeftAction(Func=ImageLeftAction, **kwargs): # pylint: disable=invalid-name
365+
def LeftAction(Func=_ImageLeftAction, **kwargs): # pylint: disable=invalid-name
368366
"""
369367
Construct a left :any:`RightActionPPerm1List` instance.
370368

0 commit comments

Comments
 (0)