mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-29 00:22:00 +00:00
fix: add reasonable argument names to enum_ methods (#2637)
* Add argument names to enum_ methods * Add test_enum::test_docstring_signatures
This commit is contained in:
parent
b72cebeb22
commit
c58758d049
@ -1628,7 +1628,7 @@ struct enum_base {
|
||||
strict_behavior; \
|
||||
return expr; \
|
||||
}, \
|
||||
name(op), is_method(m_base))
|
||||
name(op), is_method(m_base), arg("other"))
|
||||
|
||||
#define PYBIND11_ENUM_OP_CONV(op, expr) \
|
||||
m_base.attr(op) = cpp_function( \
|
||||
@ -1636,7 +1636,7 @@ struct enum_base {
|
||||
int_ a(a_), b(b_); \
|
||||
return expr; \
|
||||
}, \
|
||||
name(op), is_method(m_base))
|
||||
name(op), is_method(m_base), arg("other"))
|
||||
|
||||
#define PYBIND11_ENUM_OP_CONV_LHS(op, expr) \
|
||||
m_base.attr(op) = cpp_function( \
|
||||
@ -1644,7 +1644,7 @@ struct enum_base {
|
||||
int_ a(a_); \
|
||||
return expr; \
|
||||
}, \
|
||||
name(op), is_method(m_base))
|
||||
name(op), is_method(m_base), arg("other"))
|
||||
|
||||
if (is_convertible) {
|
||||
PYBIND11_ENUM_OP_CONV_LHS("__eq__", !b.is_none() && a.equal(b));
|
||||
@ -1730,7 +1730,7 @@ public:
|
||||
constexpr bool is_convertible = std::is_convertible<Type, Scalar>::value;
|
||||
m_base.init(is_arithmetic, is_convertible);
|
||||
|
||||
def(init([](Scalar i) { return static_cast<Type>(i); }));
|
||||
def(init([](Scalar i) { return static_cast<Type>(i); }), arg("value"));
|
||||
def("__int__", [](Type value) { return (Scalar) value; });
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
def("__long__", [](Type value) { return (Scalar) value; });
|
||||
@ -1744,7 +1744,7 @@ public:
|
||||
detail::initimpl::setstate<Base>(v_h, static_cast<Type>(arg),
|
||||
Py_TYPE(v_h.inst) != v_h.type->type); },
|
||||
detail::is_new_style_constructor(),
|
||||
pybind11::name("__setstate__"), is_method(*this));
|
||||
pybind11::name("__setstate__"), is_method(*this), arg("state"));
|
||||
}
|
||||
|
||||
/// Export enumeration entries into the parent scope
|
||||
|
@ -218,3 +218,10 @@ def test_duplicate_enum_name():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
m.register_bad_enum()
|
||||
assert str(excinfo.value) == 'SimpleEnum: element "ONE" already exists!'
|
||||
|
||||
|
||||
def test_docstring_signatures():
|
||||
for enum_type in [m.ScopedEnum, m.UnscopedEnum]:
|
||||
for attr in enum_type.__dict__.values():
|
||||
# Issue #2623/PR #2637: Add argument names to enum_ methods
|
||||
assert "arg0" not in (attr.__doc__ or "")
|
||||
|
Loading…
Reference in New Issue
Block a user