3 ms·
I used them at runtime to define the types for my (absolutely stupid) library that takes a Python function and replaces its contents with a C call. You define
by Waterluvian 4y ago
I used them at runtime to define the types for my (absolutely stupid) library that takes a Python function and replaces its contents with a C call.
You define a Python function interface but populate it with a string of C code.
- kortex 4y agoWait, so like this? def add(x: int, y: int) -> int: """ // c code int x, y return x + y """ And it compiles it and turns it into a C extension? That's...horrifying yet amazing.
- eru 4y agoThat might be a worthwhile addition to the suggestion at https://github.com/faster-cpython/ideas/issues/453 https://github.com/faster-cpython/ideas/issues/453
- BiteCode_dev 4y agoCombined with the cog (https://nedbatchelder.com/code/cog https://nedbatchelder.com/code/cog) to have the c declaration in a proper separate c file, but included in the docstring, you could have the best of both worlds.
- BiteCode_dev 4y agoThat's a neat hack!