Skip to content

Commit 36653c5

Browse files
Minor refactor
1 parent 8b952f0 commit 36653c5

File tree

3 files changed

+9
-33
lines changed

3 files changed

+9
-33
lines changed

libsemigroups_pybind11/congruence.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
CxxWrapper as _CxxWrapper,
4343
copy_cxx_mem_fns as _copy_cxx_mem_fns,
4444
to_cxx as _to_cxx,
45+
wrap_cxx_free_fn as _wrap_cxx_free_fn,
4546
)
4647

4748

@@ -144,15 +145,5 @@ def number_of_classes(self: Self) -> int:
144145
_copy_cxx_mem_fns(_CongruenceWord, Congruence)
145146

146147

147-
@_copydoc(_congruence_partition)
148-
def partition(
149-
c: Congruence, words: List[List[int]] | List[str]
150-
) -> List[List[List[int]]] | List[List[str]]:
151-
return _congruence_partition(_to_cxx(c), words)
152-
153-
154-
@_copydoc(_congruence_non_trivial_classes)
155-
def non_trivial_classes(
156-
c: Congruence, words: List[List[int]] | List[str]
157-
) -> List[List[List[int]]] | List[List[str]]:
158-
return _congruence_non_trivial_classes(c._cxx_obj, words)
148+
partition = _wrap_cxx_free_fn(_congruence_partition)
149+
non_trivial_classes = _wrap_cxx_free_fn(_congruence_non_trivial_classes)

libsemigroups_pybind11/detail/cxx_wrapper.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,8 @@ def cxx_mem_fn_wrapper(self, *args):
174174

175175
# TODO proper annotations
176176
def wrap_cxx_free_fn(cxx_free_fn: pybind11_type) -> Callable:
177-
def cxx_free_fn_wrapper(self, *args):
178-
return getattr(self._cxx_obj, cxx_free_fn.__name__)(
179-
*(to_cxx(x) for x in args)
180-
)
177+
def cxx_free_fn_wrapper(*args):
178+
return cxx_free_fn(*(to_cxx(x) for x in args))
181179

182180
cxx_free_fn_wrapper.__name__ = cxx_free_fn.__name__
183181
cxx_free_fn_wrapper.__doc__ = cxx_free_fn.__doc__

libsemigroups_pybind11/kambites.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
CxxWrapper as _CxxWrapper,
4141
copy_cxx_mem_fns as _copy_cxx_mem_fns,
4242
to_cxx as _to_cxx,
43+
wrap_cxx_free_fn as _wrap_cxx_free_fn,
4344
)
4445

4546

@@ -85,20 +86,6 @@ def small_overlap_class(self: Self) -> int:
8586
_copy_cxx_mem_fns(_KambitesWord, Kambites)
8687

8788

88-
@_copydoc(_kambites_partition)
89-
def partition(
90-
k: Kambites, words: List[List[int]] | List[str]
91-
) -> List[List[List[int]]] | List[List[str]]:
92-
return _kambites_partition(_to_cxx(k), words)
93-
94-
95-
@_copydoc(_kambites_non_trivial_classes)
96-
def non_trivial_classes(
97-
k: Kambites, words: List[List[int]] | List[str]
98-
) -> List[List[List[int]]] | List[List[str]]:
99-
return _kambites_non_trivial_classes(_to_cxx(k), words)
100-
101-
102-
@_copydoc(_kambites_normal_forms)
103-
def normal_forms(k: Kambites) -> List[List[int]] | List[str]:
104-
return _kambites_normal_forms(_to_cxx(k))
89+
partition = _wrap_cxx_free_fn(_kambites_partition)
90+
non_trivial_classes = _wrap_cxx_free_fn(_kambites_non_trivial_classes)
91+
normal_forms = _wrap_cxx_free_fn(_kambites_normal_forms)

0 commit comments

Comments
 (0)