Skip to content

New pybind11::native_enum not supported #249

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

Closed
dyollb opened this issue Apr 14, 2025 · 1 comment
Closed

New pybind11::native_enum not supported #249

dyollb opened this issue Apr 14, 2025 · 1 comment

Comments

@dyollb
Copy link

dyollb commented Apr 14, 2025

The new native_enum added to pybind11 is not supported by pybind11-stubgen. Function signatures don't seem to map the enum type from the pybind11 docstring. I am not sure if this should be fixed in pybind11 or if this is something the stubgen tool should handle.

As an example I have an enum, with following generated stubs

class eProjectionMethod(enum.IntEnum):
    kConformal: typing.ClassVar[eProjectionMethod]  # value = <eProjectionMethod.kConformal: 1>
    kRayCast: typing.ClassVar[eProjectionMethod]  # value = <eProjectionMethod.kRayCast: 2>
    kSymmetricDirichlet: typing.ClassVar[eProjectionMethod]  # value = <eProjectionMethod.kSymmetricDirichlet: 0>
    @classmethod
    def __new__(cls, value):
        ...
    def __format__(self, format_spec):

The function using this enum is SurfaceProjection, e.g. this is what help(xcm.SurfaceProjection) prints:

Help on built-in function SurfaceProjection in module XCoreModeling:

SurfaceProjection(...) method of builtins.pybind11_detail_function_record_v1_msvc_md_mscver19_debug instance
    SurfaceProjection(target: XCoreModeling.Entity, pivot: QTech.Vec3, local_z: QTech.Vec3, local_x: QTech.Vec3, entities: collections.abc.Sequence[XCoreModeling.Entity], method: XCore::Modeling::SurfProjection::eProjectionMethod = <eProjectionMethod.kSymmetricDirichlet: 0>, auto_center: bool = False) -> list[XCoreModeling.Entity]

But the stubs generated by pybind11-stubgen is:

def SurfaceProjection(target: Entity, pivot: QTech.Vec3, local_z: QTech.Vec3, local_x: QTech.Vec3, entities: collections.abc.Sequence[Entity], method: ... = ..., auto_center: bool = False) -> list[Entity]:

Note, neither the type nor the default value of method is shown and I see the error message

pybind11_stubgen - [ ERROR] In XCoreModeling.SurfaceProjection : Invalid expression 'XCore::Modeling::SurfProjection::eProjectionMethod'
pybind11_stubgen - [ ERROR] In XCoreModeling.SurfaceProjection : Invalid expression '<eProjectionMethod.kSymmetricDirichlet: 0>'

Since I would like to fix the issue I would also be willing to submit a PR (to pybind11-stubgen or pybind11 if more appropriate).

@dyollb
Copy link
Author

dyollb commented Apr 15, 2025

this is a bug in pybind11

@dyollb dyollb closed this as completed Apr 15, 2025
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