@@ -222,6 +222,31 @@ static PyObject *Proxy_str(ProxyObject *self)
222222
223223/* ------------------------------------------------------------------------- */
224224
225+ static PyObject * Proxy_fspath (ProxyObject * self )
226+ {
227+ _Py_IDENTIFIER (__fspath__ );
228+ Proxy__ENSURE_WRAPPED_OR_RETURN_NULL (self );
229+ PyObject * func = NULL ;
230+ PyObject * fspath = NULL ;
231+
232+ if (PyUnicode_Check (self -> wrapped ) || PyBytes_Check (self -> wrapped )) {
233+ Py_INCREF (self -> wrapped );
234+ return self -> wrapped ;
235+ }
236+
237+ func = _PyObject_LookupSpecial (self -> wrapped , & PyId___fspath__ );
238+ if (NULL == func ) {
239+ Py_INCREF (self -> wrapped );
240+ return self -> wrapped ;
241+ }
242+
243+ fspath = PyObject_CallFunctionObjArgs (func , NULL );
244+ Py_DECREF (func );
245+ return fspath ;
246+ }
247+
248+ /* ------------------------------------------------------------------------- */
249+
225250static PyObject * Proxy_add (PyObject * o1 , PyObject * o2 )
226251{
227252 Proxy__WRAPPED_REPLACE_OR_RETURN_NULL (o1 );
@@ -1282,7 +1307,7 @@ static PyMethodDef Proxy_methods[] = {
12821307 { "__reversed__" , (PyCFunction )Proxy_reversed , METH_NOARGS , 0 },
12831308 { "__reduce__" , (PyCFunction )Proxy_reduce , METH_NOARGS , 0 },
12841309 { "__reduce_ex__" , (PyCFunction )Proxy_reduce , METH_O , 0 },
1285- { "__fspath__" , (PyCFunction )Proxy_str , METH_NOARGS , 0 },
1310+ { "__fspath__" , (PyCFunction )Proxy_fspath , METH_NOARGS , 0 },
12861311#if PY_MAJOR_VERSION >= 3
12871312 { "__round__" , (PyCFunction )Proxy_round , METH_NOARGS , 0 },
12881313#endif
0 commit comments