Skip to content

Commit 23314e1

Browse files
Fix copy of non-function attributes
1 parent 7595d8a commit 23314e1

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/libsemigroups_pybind11/detail/cxx_wrapper.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
"""
1414

1515
from functools import update_wrapper
16-
16+
from inspect import isclass
1717
from types import MethodType
18+
1819
from typing import Any, Callable
1920
from typing_extensions import Self
2021

@@ -240,8 +241,13 @@ def copy_cxx_mem_fns(cxx_class: pybind11_type, py_class: CxxWrapper) -> None:
240241
if (not py_meth_name.startswith("_")) and py_meth_name not in dir(
241242
py_class
242243
):
243-
setattr(
244-
py_class,
245-
py_meth_name,
246-
wrap_cxx_mem_fn(getattr(cxx_class, py_meth_name)),
247-
)
244+
if not isclass(getattr(cxx_class, py_meth_name)):
245+
setattr(
246+
py_class,
247+
py_meth_name,
248+
wrap_cxx_mem_fn(getattr(cxx_class, py_meth_name)),
249+
)
250+
else:
251+
setattr(
252+
py_class, py_meth_name, getattr(cxx_class, py_meth_name)
253+
)

tests/test_knuth_bendix.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from datetime import timedelta
1616
import pytest
1717

18+
from _libsemigroups_pybind11 import Runner # pylint: disable=no-name-in-module
19+
1820
from libsemigroups_pybind11 import (
1921
KnuthBendix,
2022
LIMIT_MAX,
@@ -29,6 +31,7 @@
2931
presentation,
3032
)
3133

34+
3235
from .runner import check_runner
3336
from .cong_common import check_congruence_common_return_policy
3437

@@ -393,6 +396,12 @@ def test_knuth_bendix_return_policy():
393396
assert kb.gilman_graph_node_labels() is not kb.gilman_graph_node_labels()
394397

395398

399+
def test_knuth_bendix_runner_state():
400+
p = Presentation([0, 1])
401+
kb = KnuthBendix(congruence_kind.twosided, p)
402+
assert isinstance(kb.state(0), Runner.state)
403+
404+
396405
# TODO(0) Does the alphabet bug persist? YES: the test fails
397406
# def test_alphabet_bug():
398407
# p = Presentation("".join(chr(i) for i in range(-126, 128)))

0 commit comments

Comments
 (0)