pybind11-stubgen icon indicating copy to clipboard operation
pybind11-stubgen copied to clipboard

Alias stub generation

Open HaarigerHarald opened this issue 3 years ago • 1 comments

Hi,

I came across an issue with alias'. This snippet

#include <pybind11/pybind11.h>

PYBIND11_MODULE(foo, m)
{   
    struct Color
    {
        int value;
    };
    
    pybind11::class_<Color>(m, "Color")
        .def_readwrite("value", &Color::value);

    m.attr("Colour") = m.attr("Color");
}

produces

import foo
import typing

__all__ = [
    "Colour"
    "Color"
]

class Color():
    def value(self) -> int:
        """
        :type: int
        """
    pass
class Color():
    pass

when it should be

import foo
import typing

__all__ = [
    "Colour"
    "Color"
]

class Color():
    def value(self) -> int:
        """
        :type: int
        """
    pass
Colour = foo.Color

The pull request should fix this as well as module, function and class member alias'.

HaarigerHarald avatar Sep 28 '21 19:09 HaarigerHarald

Hi, thanks for contribution! Patch looks good to me. I'll add a couple of tests to cover this PR and merge it shortly.

sizmailov avatar Sep 29 '21 08:09 sizmailov

Sorry for taking it that long.

Merged as 9c71cde2cd0ae8781d44902a24f2b4e85d97c9ce

sizmailov avatar Mar 10 '23 12:03 sizmailov