Hacker News new | past | comments | ask | show | jobs | submit login

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.




Wait, 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.


That might be a worthwhile addition to the suggestion at https://github.com/faster-cpython/ideas/issues/453


Combined with the 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.


That's a neat hack!




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: