Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to generate a .pyi file for a C Extension using stubgen

450 views
Skip to first unread message

Marco Sulla

unread,
Jul 29, 2022, 2:30:42 PM7/29/22
to
I tried to follow the instructions here:

https://mypy.readthedocs.io/en/stable/stubgen.html

but the instructions about creating a stub for a C Extension are a little
mysterious. I tried to use it on the .so file without luck.

Barry

unread,
Jul 29, 2022, 5:23:25 PM7/29/22
to


> On 29 Jul 2022, at 19:33, Marco Sulla <Marco.Sul...@gmail.com> wrote:
>
> I tried to follow the instructions here:
>
> https://mypy.readthedocs.io/en/stable/stubgen.html
>
> but the instructions about creating a stub for a C Extension are a little
> mysterious. I tried to use it on the .so file without luck.

It says that stubgen works on .py files not .so files.
You will need to write the .pyi for your .so manually.

The docs could do with splitting the need for .pyi for .so
away from the stubgen description.

Barry


> --
> https://mail.python.org/mailman/listinfo/python-list
>

Marco Sulla

unread,
Jul 30, 2022, 5:30:41 AM7/30/22
to
On Fri, 29 Jul 2022 at 23:23, Barry <ba...@barrys-emacs.org> wrote:
>
>
>
> > On 29 Jul 2022, at 19:33, Marco Sulla <Marco.Sul...@gmail.com> wrote:
> >
> > I tried to follow the instructions here:
> >
> > https://mypy.readthedocs.io/en/stable/stubgen.html
> >
> > but the instructions about creating a stub for a C Extension are a little
> > mysterious. I tried to use it on the .so file without luck.
>
> It says that stubgen works on .py files not .so files.
> You will need to write the .pyi for your .so manually.
>
> The docs could do with splitting the need for .pyi for .so
> away from the stubgen description.

But it says:

"Mypy includes the stubgen tool that can automatically generate stub
files (.pyi files) for Python modules and C extension modules."

I tried stubgen -m modulename, but it generates very little code.

Barry

unread,
Jul 30, 2022, 9:59:42 AM7/30/22
to


> On 30 Jul 2022, at 10:30, Marco Sulla <Marco.Sul...@gmail.com> wrote:
>
> On Fri, 29 Jul 2022 at 23:23, Barry <ba...@barrys-emacs.org> wrote:
>>
>>
>>
>>>> On 29 Jul 2022, at 19:33, Marco Sulla <Marco.Sul...@gmail.com> wrote:
>>>
>>> I tried to follow the instructions here:
>>>
>>> https://mypy.readthedocs.io/en/stable/stubgen.html
>>>
>>> but the instructions about creating a stub for a C Extension are a little
>>> mysterious. I tried to use it on the .so file without luck.
>>
>> It says that stubgen works on .py files not .so files.
>> You will need to write the .pyi for your .so manually.
>>
>> The docs could do with splitting the need for .pyi for .so
>> away from the stubgen description
>
> But it says:
>
> "Mypy includes the stubgen tool that can automatically generate stub
> files (.pyi files) for Python modules and C extension modules."
>
> I tried stubgen -m modulename, but it generates very little code.

Oh…

From the .so I am struggling to figure out how it could ever work reliably.
I cannot see that there is enough information in a useful form to allow
the tool to work.

Barry

>

0 new messages