2
0
mirror of https://github.com/boostorg/python.git synced 2026-02-03 09:22:17 +00:00

Toons of changes to improve error handling.

Added attributes function.__name__, function.__signature__, and
the dir(function) feature


[SVN r8313]
This commit is contained in:
Ullrich Köthe
2000-11-23 23:03:24 +00:00
parent f7ad50166d
commit e3fe2d02ee
19 changed files with 1423 additions and 1721 deletions

View File

@@ -197,8 +197,7 @@ namespace detail
};
};
// Fully specialize define_operator for all operators defined in operator_id above.
// Every specialization defines one function object for normal operator calls and one
// for operator calls with operands reversed ("__r*__" function variants).
@@ -214,15 +213,20 @@ namespace detail
{ \
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
{ \
tuple args(ref(arguments, ref::increment_count)); \
tuple args(ref(arguments, ref::increment_count)); \
\
return BOOST_PYTHON_CONVERSION::to_python( \
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), python::type<Left>()) oper \
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), python::type<Right>())); \
} \
\
const char* description() const \
{ return "__" #id "__"; } \
string function_name() const \
{ return string(name()); } \
\
PyObject* description() const \
{ \
return function_signature(python::type<Left>(), python::type<Right>()); \
} \
}; \
\
template <class Right, class Left> \
@@ -230,15 +234,20 @@ namespace detail
{ \
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
{ \
tuple args(ref(arguments, ref::increment_count)); \
tuple args(ref(arguments, ref::increment_count)); \
\
return BOOST_PYTHON_CONVERSION::to_python( \
return BOOST_PYTHON_CONVERSION::to_python( \
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), python::type<Left>()) oper \
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), python::type<Right>())); \
} \
\
const char* description() const \
{ return "__r" #id "__"; } \
string function_name() const \
{ return string(rname()); } \
\
PyObject* description() const \
{ \
return function_signature(python::type<Left>(), python::type<Right>()); \
} \
\
}; \
\
@@ -255,14 +264,19 @@ namespace detail
{ \
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
{ \
tuple args(ref(arguments, ref::increment_count)); \
tuple args(ref(arguments, ref::increment_count)); \
\
return BOOST_PYTHON_CONVERSION::to_python( \
return BOOST_PYTHON_CONVERSION::to_python( \
oper(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), python::type<operand>()))); \
} \
\
const char* description() const \
{ return "__" #id "__"; } \
string function_name() const \
{ return string(name()); } \
\
PyObject* description() const \
{ \
return function_signature(python::type<operand>()); \
} \
}; \
\
static const char * name() { return "__" #id "__"; } \
@@ -317,8 +331,13 @@ namespace detail
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), python::type<Right>())));
}
const char* description() const
{ return "__pow__"; }
string function_name() const
{ return string(name()); }
PyObject* description() const
{
return function_signature(python::type<Left>(), python::type<Right>());
}
};
@@ -331,7 +350,7 @@ namespace detail
if (args.size() == 3 && args[2]->ob_type != Py_None->ob_type)
{
PyErr_SetString(PyExc_TypeError, "bad operand type(s) for pow()");
PyErr_SetString(PyExc_TypeError, "'__pow__' expected 2 arguments, got 3.");
throw argument_error();
}
@@ -340,8 +359,13 @@ namespace detail
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), python::type<Right>())));
}
const char* description() const
{ return "__rpow__"; }
string function_name() const
{ return string(rname()); }
PyObject* description() const
{
return function_signature(python::type<Left>(), python::type<Right>());
}
};
@@ -374,8 +398,13 @@ namespace detail
return res;
}
const char* description() const
{ return "__divmod__"; }
string function_name() const
{ return string(name()); }
PyObject* description() const
{
return function_signature(python::type<Left>(), python::type<Right>());
}
};
@@ -399,9 +428,13 @@ namespace detail
return res;
}
const char* description() const
{ return "__rdivmod__"; }
string function_name() const
{ return string(rname()); }
PyObject* description() const
{
return function_signature(python::type<Left>(), python::type<Right>());
}
};
static const char * name() { return "__divmod__"; }
@@ -430,8 +463,13 @@ namespace detail
0) ;
}
const char* description() const
{ return "__cmp__"; }
string function_name() const
{ return string(name()); }
PyObject* description() const
{
return function_signature(python::type<Left>(), python::type<Right>());
}
};
@@ -452,8 +490,13 @@ namespace detail
0) ;
}
const char* description() const
{ return "__rcmp__"; }
string function_name() const
{ return string(rname()); }
PyObject* description() const
{
return function_signature(python::type<Left>(), python::type<Right>());
}
};
@@ -488,8 +531,13 @@ namespace detail
#endif
}
const char* description() const
{ return "__str__"; }
string function_name() const
{ return string(name()); }
PyObject* description() const
{
return function_signature(python::type<operand>());
}
};