@@ -65,22 +65,14 @@ def __init__(
6565 required_kwargs = (),
6666 optional_kwargs = (),
6767 ** kwargs ,
68- ):
69- if (
70- len (args ) == 1
71- and len (kwargs ) == 0
72- and type (args [0 ]) in self ._all_wrapped_cxx_types
73- ):
68+ ) -> None :
69+ if len (args ) == 1 and len (kwargs ) == 0 and type (args [0 ]) in self ._all_wrapped_cxx_types :
7470 # Copy constructor like construction directly from cxx object
7571 self ._cxx_obj = args [0 ]
7672 self .py_template_params = self .py_template_params_from_cxx_obj ()
7773 return
7874
79- if (
80- not len (required_kwargs )
81- <= len (kwargs )
82- <= len (required_kwargs ) + len (optional_kwargs )
83- ):
75+ if not len (required_kwargs ) <= len (kwargs ) <= len (required_kwargs ) + len (optional_kwargs ):
8476 raise TypeError (
8577 f"expected between { len (required_kwargs )} and "
8678 f"{ len (required_kwargs ) + len (optional_kwargs )} "
@@ -119,9 +111,7 @@ def __getattr__(self: Self, name: str):
119111 def cxx_fn_wrapper (* args ) -> Any :
120112 if len (args ) == 1 and isinstance (args [0 ], list ):
121113 args = args [0 ]
122- return getattr (self ._cxx_obj , name )(
123- [to_cxx (x ) for x in args ]
124- )
114+ return getattr (self ._cxx_obj , name )([to_cxx (x ) for x in args ])
125115 return getattr (self ._cxx_obj , name )(* (to_cxx (x ) for x in args ))
126116
127117 return cxx_fn_wrapper
@@ -136,18 +126,14 @@ def __copy__(self: Self) -> Self:
136126 if self ._cxx_obj is not None :
137127 if hasattr (self ._cxx_obj , "__copy__" ):
138128 return to_py (self ._cxx_obj .__copy__ ())
139- raise NotImplementedError (
140- f"{ type (self ._cxx_obj )} has no member named __copy__"
141- )
129+ raise NotImplementedError (f"{ type (self ._cxx_obj )} has no member named __copy__" )
142130 raise NameError ("_cxx_obj has not been defined" )
143131
144132 def __eq__ (self : Self , that ) -> bool :
145133 if self ._cxx_obj is not None :
146134 if hasattr (self ._cxx_obj , "__eq__" ):
147135 return self ._cxx_obj .__eq__ (that ._cxx_obj )
148- raise NotImplementedError (
149- f"{ type (self ._cxx_obj )} has no member named __eq__"
150- )
136+ raise NotImplementedError (f"{ type (self ._cxx_obj )} has no member named __eq__" )
151137 raise NameError ("_cxx_obj has not been defined" )
152138
153139 def py_template_params_from_cxx_obj (self : Self ) -> tuple :
@@ -166,9 +152,9 @@ def init_cxx_obj(self: Self, *args) -> None:
166152 defined.
167153 """
168154 assert self .py_template_params is not None
169- self ._cxx_obj = self ._py_template_params_to_cxx_type [
170- self . py_template_params
171- ]( * ( to_cxx ( x ) for x in args ) )
155+ self ._cxx_obj = self ._py_template_params_to_cxx_type [self . py_template_params ](
156+ * ( to_cxx ( x ) for x in args )
157+ )
172158
173159
174160# TODO proper annotations
@@ -184,17 +170,13 @@ def cxx_mem_fn_wrapper(self, *args):
184170 # TODO move the first if-clause into to_cxx?
185171 if len (args ) == 1 and isinstance (args [0 ], list ):
186172 args = [[to_cxx (x ) for x in args [0 ]]]
187- result = getattr (to_cxx (self ), cxx_mem_fn .__name__ )(
188- * (to_cxx (x ) for x in args )
189- )
173+ result = getattr (to_cxx (self ), cxx_mem_fn .__name__ )(* (to_cxx (x ) for x in args ))
190174 if result is to_cxx (self ):
191175 return self
192176 if type (result ) in _CXX_WRAPPED_TYPE_TO_PY_TYPE :
193177 cached_val = f"_cached_return_value_{ cxx_mem_fn .__name__ } "
194178 # TODO use args too in cached_val?
195- if hasattr (self , cached_val ) and result is to_cxx (
196- getattr (self , cached_val )
197- ):
179+ if hasattr (self , cached_val ) and result is to_cxx (getattr (self , cached_val )):
198180 return getattr (self , cached_val )
199181 result = _CXX_WRAPPED_TYPE_TO_PY_TYPE [type (result )](result )
200182 setattr (self , cached_val , result )
@@ -228,9 +210,7 @@ def copy_cxx_mem_fns(cxx_class: pybind11_type, py_class: CxxWrapper) -> None:
228210 that call the cxx member function on the _cxx_obj.
229211 """
230212 for py_meth_name in dir (cxx_class ):
231- if (not py_meth_name .startswith ("_" )) and py_meth_name not in dir (
232- py_class
233- ):
213+ if (not py_meth_name .startswith ("_" )) and py_meth_name not in dir (py_class ):
234214 setattr (
235215 py_class ,
236216 py_meth_name ,
0 commit comments