Skip to content

Commit df9ceeb

Browse files
Action renovation x2
1 parent e931639 commit df9ceeb

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

libsemigroups_pybind11/action.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
the Action class from libsemigroups.
1515
"""
1616

17-
from typing import Any, Union, Iterator
17+
from typing import Any, Union, Iterator, TypeVar as _TypeVar
1818
from typing_extensions import Self as _Self
1919

2020
from _libsemigroups_pybind11 import (
@@ -58,12 +58,8 @@
5858
)
5959

6060

61-
# TODO doc
62-
class Action(_CxxWrapper):
63-
"""
64-
The documentation for this class is taken from RightActionPPerm1List in
65-
src/action.cpp!
66-
"""
61+
class Action(_CxxWrapper): # pylint: disable=missing-class-docstring
62+
__doc__ = _RightActionPPerm1List.__doc__
6763

6864
_py_template_params_to_cxx_type = {
6965
(_BMat8, _BMat8, _ImageRightAction, side.right): _RightActionBMat8BMat8,
@@ -177,15 +173,22 @@ def __init__(self: _Self, **kwargs):
177173
self.Point = kwargs["Point"]
178174
self.Func = kwargs["Func"]
179175
self.Side = kwargs["Side"]
180-
self.init()
181176

182-
def __getattr__(self: _Self, meth_name: str) -> Any:
183-
self._init_cxx_obj()
184-
return super().__getattr__(meth_name)
177+
self.py_template_params = (
178+
kwargs["Element"],
179+
kwargs["Point"],
180+
kwargs["Func"],
181+
kwargs["Side"],
182+
)
183+
# The following are temporary places to hold things required to init
184+
# the _cxx_obj, whose type is determined in _init_cxx_obj
185+
self._generators = []
186+
self._seeds = []
187+
self._cache_scc_multipliers = False
188+
self._reserve = 0
185189

186190
def _init_cxx_obj(self: _Self) -> None:
187-
# pylint: disable=attribute-defined-outside-init
188-
if self._cxx_obj is not None:
191+
if _to_cxx(self) is not None:
189192
return
190193

191194
if len(self._generators) == 0:
@@ -205,13 +208,19 @@ def _init_cxx_obj(self: _Self) -> None:
205208

206209
self._cxx_obj = cxx_obj_t()
207210

211+
# Use the cached values to setup the _cxx_obj
208212
for x in self._generators:
209213
self._cxx_obj.add_generator(_to_cxx(x))
210214
for x in self._seeds:
211215
self._cxx_obj.add_seed(_to_cxx(x))
212216
self._cxx_obj.cache_scc_multipliers(self._cache_scc_multipliers)
213217
self._cxx_obj.reserve(self._reserve)
214218

219+
# Intercept calls to __getattr__ so that we can init the cxx_obj
220+
def __getattr__(self: _Self, meth_name: str) -> Any:
221+
self._init_cxx_obj()
222+
return super().__getattr__(meth_name)
223+
215224
def __repr__(self: _Self) -> str:
216225
result = super().__repr__()
217226
if result:

0 commit comments

Comments
 (0)