14
14
the Action class from libsemigroups.
15
15
"""
16
16
17
- from typing import Any , Union , Iterator
17
+ from typing import Any , Union , Iterator , TypeVar as _TypeVar
18
18
from typing_extensions import Self as _Self
19
19
20
20
from _libsemigroups_pybind11 import (
58
58
)
59
59
60
60
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__
67
63
68
64
_py_template_params_to_cxx_type = {
69
65
(_BMat8 , _BMat8 , _ImageRightAction , side .right ): _RightActionBMat8BMat8 ,
@@ -177,15 +173,22 @@ def __init__(self: _Self, **kwargs):
177
173
self .Point = kwargs ["Point" ]
178
174
self .Func = kwargs ["Func" ]
179
175
self .Side = kwargs ["Side" ]
180
- self .init ()
181
176
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
185
189
186
190
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 :
189
192
return
190
193
191
194
if len (self ._generators ) == 0 :
@@ -205,13 +208,19 @@ def _init_cxx_obj(self: _Self) -> None:
205
208
206
209
self ._cxx_obj = cxx_obj_t ()
207
210
211
+ # Use the cached values to setup the _cxx_obj
208
212
for x in self ._generators :
209
213
self ._cxx_obj .add_generator (_to_cxx (x ))
210
214
for x in self ._seeds :
211
215
self ._cxx_obj .add_seed (_to_cxx (x ))
212
216
self ._cxx_obj .cache_scc_multipliers (self ._cache_scc_multipliers )
213
217
self ._cxx_obj .reserve (self ._reserve )
214
218
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
+
215
224
def __repr__ (self : _Self ) -> str :
216
225
result = super ().__repr__ ()
217
226
if result :
0 commit comments