#🔒 pyi from runtime module object

21 messages · Page 1 of 1 (latest)

frigid garnet
#

Hello! I’m looking for a way to automatically generate a .pyi file from a runtime module object, bonus points for integrating type annotations.

I think this can be solved with some hacky inspect.getmembers module traversal, but I’d much rather use some readymade solution if one exists.

charred vaultBOT
#

@frigid garnet

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

green current
#

What is the module written in?

#

note that runtime types aren't always indicative of the actual types, such as with overloads, generics, and function arguments, unions, etc

frigid garnet
# green current What is the module written in?

The module is an extension module from Cython. Not just one, which I could manage doing manually, but I’m trying to solve this kinda-generally because IMO this is a lacking area of Cython development. I’ve run through the major solutions - cythonbuilder, CyStub, even a pretty good PEG for Cython but nothing worked exactly as I wanted it to.

Loading in the module is obviously a massive security risk and this will be done for only trusted code but I think it has the best chance of producing generally useful pyi files, more so than static analysis

green current
#

!pip cythonbuilder

charred vaultBOT
#

CythonBuilder; automated compiling and packaging of Cython code

Released on <t:1730728806:D>.

frigid garnet
green current
#

apparently cythonbuilder interface. Was reading from stackoverflow.

#

I think that's the extent of my helpfulness. I've googled all I can google.

frigid garnet
# green current This may be useful. Someone else also didn't find cythonbuilder good enough. htt...

Right, that’s what I assumed you meant. cy_interface is the function I’d use in setup.

Also tried CythonPEG - it’s very good and I’m using it currently, but I believe also suffers from the same issue of not exposing class members which aren’t functions but are very much still visible to Python. Fixed it for my workflow, but out of the box it also exposes cdef functions on classes that are supposed to be private (and indeed are not usable in Python)

green current
#

sounds like a bug report

frigid garnet
#

Eh, cythonbuilder is perfectly usable as it stands and will probably work well for most people. I might open an issue just to have it on their minds, but I probably won’t be contributing

I do agree that I should open an issue with PEG, tho. I might even give them a PR with my small fix

#

I’ll see how far I can get with module traversal. Honestly just a : Any-full pyi file would be perfect for me, just something that offers autocomplete on types and imports

#

Which shouldn’t (every time I use that word I feel my weekend going down the drain) be that difficult

charred vaultBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.