Skip to content

Commit bfab8e1

Browse files
Some more cleanups in cxx_wrapper.py
1 parent f9af0cb commit bfab8e1

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

libsemigroups_pybind11/detail/cxx_wrapper.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def to_py(x: Any, *args) -> Any:
4242
This function returns the CxxWrapper type wrapping an instance of <x> if
4343
<x> is an instance of CxxWrapper type, and <x> o/w.
4444
"""
45-
# TODO replace with isinstance(x, CxxWrapper)
4645
if type(x) in _CXX_WRAPPED_TYPE_TO_PY_TYPE:
4746
return _CXX_WRAPPED_TYPE_TO_PY_TYPE[type(x)](x, *args)
4847
return x
@@ -137,10 +136,7 @@ def __repr__(self: Self) -> str:
137136
def __copy__(self: Self) -> Self:
138137
if self._cxx_obj is not None:
139138
if hasattr(self._cxx_obj, "__copy__"):
140-
# TODO use to_py
141-
return _CXX_WRAPPED_TYPE_TO_PY_TYPE[type(self._cxx_obj)](
142-
self._cxx_obj.__copy__()
143-
)
139+
return to_py(self._cxx_obj.__copy__())
144140
raise NotImplementedError(
145141
f"{type(self._cxx_obj)} has no member named __copy__"
146142
)
@@ -219,11 +215,7 @@ def wrap_cxx_free_fn(cxx_free_fn: pybind11_type) -> Callable:
219215
"""
220216

221217
def cxx_free_fn_wrapper(*args):
222-
# TODO use to_py
223-
result = cxx_free_fn(*(to_cxx(x) for x in args))
224-
if type(result) in _CXX_WRAPPED_TYPE_TO_PY_TYPE:
225-
return _CXX_WRAPPED_TYPE_TO_PY_TYPE[type(result)](result)
226-
return result
218+
return to_py(cxx_free_fn(*(to_cxx(x) for x in args)))
227219

228220
update_wrapper(cxx_free_fn_wrapper, cxx_free_fn)
229221
return cxx_free_fn_wrapper
@@ -235,10 +227,7 @@ def copy_cxx_mem_fns(cxx_class: pybind11_type, py_class: CxxWrapper) -> None:
235227
that call the cxx member function on the _cxx_obj.
236228
"""
237229
for py_meth_name in dir(cxx_class):
238-
if (
239-
(not py_meth_name.startswith("_")) and py_meth_name not in dir(py_class)
240-
# and type(getattr(cxx_class, py_meth_name)) is MethodType
241-
):
230+
if (not py_meth_name.startswith("_")) and py_meth_name not in dir(py_class):
242231
setattr(
243232
py_class,
244233
py_meth_name,

0 commit comments

Comments
 (0)