I’m looking to learn about this language from a technical level, and any searches I do on today’s search engines is just going to return guides to writing Python code, which is not what I want.

I understand how C++ works. For example, I know that virtual functions are stored as a trap table in an object’s instance, and the function is wrapped around something that decodes that trap table from this object instance.

I’m wondering if there’s something that goes into that level of technicality with python. For example, I would want to know how function declarations (and re-declarations) work in python. Is the bytecode stored as a heap object which can be freed just as a regular heap object? Is it a map of strings within the current stack context? How does creating a thread handle it?

  • bitcrafter@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    1 day ago

    If you have not already read through it, there is a ton of useful information about Python’s data model in the user manual; it is my go-to resource when I want to do weird stuff with metaclasses and the like.

    Furthermore, you might find it interesting to peruse the C code that is generated by Cython, because it gives you a concrete view of the kinds of steps that Python has to go through from a C perspective to work within its data model. (Cython is a bit faster than Python because it does not have to interpret bytecode, but unless you use special directives it still has to e.g. do general attribute lookups whenever you interact with a Python value, even if the value is an integer, and maintain reference counts.)

    Finally, you might also get a lot out of skimming through the CPython bytecode instructions, as this has a lot of interesting details about how the bytecode interpreter works in practice.