Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: nanobind referencing non-existent value __new__ in generated type for enumeration #961

Open
breathe opened this issue Mar 4, 2025 · 0 comments

Comments

@breathe
Copy link
Contributor

breathe commented Mar 4, 2025

Problem description

mypy is issuing an error like this when type checking generated type stub:

> mypy
zephyrus/lib/native/zephyrus_native_ext.pyi:675: error: Name "__new__" is not defined  [name-defined]

(the full .pyi file)

import enum


# this code is generated

class SUPLMessage:
    class Type(enum.Enum):
        _new_member_ = __new__

        _use_args_: bool = False

        _member_names_: list = ...

        _member_map_: dict = ...

        _value2member_map_: dict = ...

        _unhashable_values_: list = []

        _value_repr_: None = None

        Empty = 0

        ProvideAssistance = 1

        ProvideCapabilities = 2

        ProvideLocation = 3

        RequestAssistance = 4

        RequestCapabilities = 5

        RequestLocation = 6

Reproducible example code

#pragma GCC diagnostic push

// nanobind uses these extensions.
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wzero-length-array"
#pragma GCC diagnostic ignored "-Wnested-anon-types"
#pragma GCC diagnostic ignored "-Wcast-align"

#include <nanobind/nanobind.h>

#include <nanobind/stl/pair.h>
#include <nanobind/stl/tuple.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/map.h>
#include <nanobind/stl/vector.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/unique_ptr.h>
#include <nanobind/eigen/dense.h>

#pragma GCC diagnostic pop

namespace nb = nanobind;

class Message
{
  public:
    enum class Type : uint8_t
    {
        EMPTY,
        PROVIDE_ASSISTANCE,
        PROVIDE_CAPABILITIES,
        PROVIDE_LOCATION,
        REQUEST_ASSISTANCE,
        REQUEST_CAPABILITIES,
        REQUEST_LOCATION,
    };

    virtual ~Message() = default;

    Message(const Message &) = delete;
    auto operator=(Message &) -> Message & = delete;

    Message(Message &&other) noexcept = default;
    auto operator=(Message &&other) noexcept -> Message & = default;

};

NB_MODULE(zephyrus_native_ext, m)
{

    nb::class_<Message> message(m, "SUPLMessage");

    nb::enum_<Message::Type>(message, "Type")
        .value("Empty", Message::Type::EMPTY)
        .value("ProvideAssistance", Message::Type::PROVIDE_ASSISTANCE)
        .value("ProvideCapabilities", Message::Type::PROVIDE_CAPABILITIES)
        .value("ProvideLocation", Message::Type::PROVIDE_LOCATION)
        .value("RequestAssistance", Message::Type::REQUEST_ASSISTANCE)
        .value("RequestCapabilities", Message::Type::REQUEST_CAPABILITIES)
        .value("RequestLocation", Message::Type::REQUEST_LOCATION);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant