Skip to content

Allow __doc__ to be settable on enums #2275

Closed
@AWhetter

Description

@AWhetter

Issue description

Currently when declaring an enum, the __doc__ attribute of the enum is not settable. However the __doc__ on object() is settable so it makes sense for the __doc__ of an enum to be settable also.

The use case where this is coming up:
I'm generating type stubs of a pybind module using stubgen. When running mypy with the generated stubs I see the following error:

Signature of "__doc__" incompatible with supertype of "object".

Potential Fix

I'm not sure what the right fix is here. I can of course make the __doc__ property writable on all enum objects, but implementing that properly would mean adding a new attribute to enum objects and that seems wasteful.

Reproducible example code

# include <pybind11/pybind11.h>

namespace py = pybind11;

enum Numbers {
    zero,
    one
};

PYBIND11_MODULE(numbers, m) {
    py::enum_<Numbers>(m, "Numbers")
        .value("zero", zero)
        .value("one", one)
        .export_values()
    ;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions