Fix enum's `__str__` docstring (#4827)

* fix: Enum __str__ function name

* tests: Test enum.__str__.__doc__
This commit is contained in:
Sergei Izmailov 2023-08-31 06:20:46 +09:00 committed by GitHub
parent 1adac5a5b1
commit e705fb5f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -2014,7 +2014,7 @@ struct enum_base {
object type_name = type::handle_of(arg).attr("__name__");
return pybind11::str("{}.{}").format(std::move(type_name), enum_name(arg));
},
name("name"),
name("__str__"),
is_method(m_base));
if (options::show_enum_members_docstring()) {

View File

@ -264,3 +264,8 @@ def test_docstring_signatures():
for attr in enum_type.__dict__.values():
# Issue #2623/PR #2637: Add argument names to enum_ methods
assert "arg0" not in (attr.__doc__ or "")
def test_str_signature():
for enum_type in [m.ScopedEnum, m.UnscopedEnum]:
assert enum_type.__str__.__doc__.startswith("__str__")