Skip to content

Uncaught Error: None value in Pybind enum makes pyi contain syntax errors #258

Description

@parker-research

Take, for example, the following Pybind C++ enum:

    py::enum_<EvalFlags>(m, "EvalFlags")
        .value("None", EvalFlags::None)
        .value("IsScript", EvalFlags::IsScript)
        .value("CacheResults", EvalFlags::CacheResults)

The output of the type stub generation is:

import enum

class EvalFlags(enum.Enum):
    None = 0
    IsScript = 1
    CacheResults = 2

This is a syntax error, because None is a protected keyword in Python. Instead, during the stub generation/code parsing, an error should be thrown saying that "None" is not a valid enum key. It could even suggest renaming to None_, as is common.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions