Automatic generation of .pyi typing stub files

325 views
Skip to first unread message

Robin Jarry

unread,
Jul 9, 2020, 12:53:41 PM7/9/20
to python-cffi
Hi all,

I am currently getting my head around type hinting in python 3. For those who are not familiar with this concept, it has been introduced in PEP 484.


When working with compiled C extensions, the only way for static type checkers to work properly is to provide "stub" files which contain the typing annotations about the symbols exported by the compiled modules.


I wonder if it would be possible for CFFI to generate these stub files while generating the C code for the compiled extensions. I do not have enough knowledge of CFFI inner workings to attempt such a task by myself but I would like to help.

What do you think?

Thanks in advance for your feedback.

-- 
Robin

Armin Rigo

unread,
Jul 9, 2020, 6:10:16 PM7/9/20
to pytho...@googlegroups.com
Hi,

On Thu, 9 Jul 2020 at 18:53, Robin Jarry <robin...@6wind.com> wrote:
> I am currently getting my head around type hinting in python 3. For those who are not familiar with this concept, it has been introduced in PEP 484.

I have no interest in this PEP 484 myself. But yes, it looks doable
to produce whatever extra information you need along with the
generated C code, by extending cffi/recompiler.py.


A bientôt,

Armin.

Robin Jarry

unread,
Jul 10, 2020, 3:07:11 AM7/10/20
to pytho...@googlegroups.com
Hi Armin,

2020-07-10, Armin Rigo:
> I have no interest in this PEP 484 myself. But yes, it looks doable
> to produce whatever extra information you need along with the
> generated C code, by extending cffi/recompiler.py.

Merci for the pointers. I'll see if I can attempt a draft pull request.

Robin

Armin Rigo

unread,
Jul 10, 2020, 11:21:56 AM7/10/20
to pytho...@googlegroups.com
Hi again, 

Let me warn you that I may be unwilling to merge a complex set of new code inside cffi. You should probably focus on making an independent, separately distributed add-on. But you can likely depend on the internals of cffi in your code: I do not expect cffi to evolve a lot in the future.


A bientôt, 
Armin 

Daniel Holth

unread,
Jul 10, 2020, 3:05:40 PM7/10/20
to python-cffi
Here's my quick & dirty compiler that iterates over cffi's declarations to build SDL-specific Python wrappers. https://github.com/dholth/pysdl2-cffi/blob/master/builder/builder.py

--
-- python-cffi: To unsubscribe from this group, send email to python-cffi...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/python-cffi?hl=en
---
You received this message because you are subscribed to the Google Groups "python-cffi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-cffi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-cffi/CAMSv6X18ikNqY7M_N8qfP64QQ0oQZfx1DzSCipCaCMNzTcBzuw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages