sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
218 stars 44 forks source link

Modify Enum keyword default from its __repr__ to its __str__ by default? #192

Closed ringohoffman closed 7 months ago

ringohoffman commented 7 months ago

I found this while running on taichi:

class Program:
    def create_ndarray(self, layout: Layout = <Layout.NULL: 2>) -> Ndarray:
        ...

This expression could be made syntactically correct just by extracting out the __str__ repr of the enum value like:

class Program:
    def create_ndarray(self, layout: Layout = Layout.NULL) -> Ndarray:
        ...

Should we do this by default?

ringohoffman commented 7 months ago

Actually it seems like this is already done:

https://github.com/sizmailov/pybind11-stubgen/blob/adbd6a335795b96227e78b3483cafb278f1c7a77/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/enum.pyi#L63-L65

ringohoffman commented 7 months ago

It seems like

--enum-class-locations="Layout:taichi._lib.core.taichi_python"

was the key! Should have read the error message closer!