Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are python built-ins always C extensions (even on PyPy)?

I'm working on a documentation API for Python I'm calling Python Docs, and I've noticed that almost all built-ins can't be accessed by my static analysis suite, because they are almost exclusively C modules. As far as I can remember, I can't think of any exceptions to this rule.

The first part of my question is simply, does being a built-in module presuppose being a C-extension in CPython?

Assuming that this might be the case, I compiled a fresh pypy runtime and tried using my project against with the built-ins from pypy. I was surprised to find that this didn't work either.

Why aren't PyPy modules available AST objects if they're pure Python? Is this a side-effect of PyPy being hosted on a JIT?

like image 637
mvanveen Avatar asked Mar 30 '12 03:03

mvanveen


1 Answers

PyPy is two parts -- the Python interpreter and the translation toolchain.

The translation toolchain translates / "compiles" the interpreter from RPython into machine code.

So although PyPy is written in a language that is a subset of Python, it's not Python when you use it.

You should read the compiler section of the PyPy Parser docs and this blog post that describes that the AST features in PyPy mirror those in CPython.

like image 168
agf Avatar answered Nov 15 '22 09:11

agf