@@ -42,7 +42,6 @@ def to_py(x: Any, *args) -> Any:
42
42
This function returns the CxxWrapper type wrapping an instance of <x> if
43
43
<x> is an instance of CxxWrapper type, and <x> o/w.
44
44
"""
45
- # TODO replace with isinstance(x, CxxWrapper)
46
45
if type (x ) in _CXX_WRAPPED_TYPE_TO_PY_TYPE :
47
46
return _CXX_WRAPPED_TYPE_TO_PY_TYPE [type (x )](x , * args )
48
47
return x
@@ -137,10 +136,7 @@ def __repr__(self: Self) -> str:
137
136
def __copy__ (self : Self ) -> Self :
138
137
if self ._cxx_obj is not None :
139
138
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__ ())
144
140
raise NotImplementedError (
145
141
f"{ type (self ._cxx_obj )} has no member named __copy__"
146
142
)
@@ -219,11 +215,7 @@ def wrap_cxx_free_fn(cxx_free_fn: pybind11_type) -> Callable:
219
215
"""
220
216
221
217
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 )))
227
219
228
220
update_wrapper (cxx_free_fn_wrapper , cxx_free_fn )
229
221
return cxx_free_fn_wrapper
@@ -235,10 +227,7 @@ def copy_cxx_mem_fns(cxx_class: pybind11_type, py_class: CxxWrapper) -> None:
235
227
that call the cxx member function on the _cxx_obj.
236
228
"""
237
229
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 ):
242
231
setattr (
243
232
py_class ,
244
233
py_meth_name ,
0 commit comments