[capi-sig] Some type inference for python?

Ulf Worsoe ulf.worsoe at mosek.com
Tue May 25 09:39:55 CEST 2010


Hi,

The C API does not provide any code-inspection functionality like that
directly, but you can access the byte-code objects of a
python-function (the "func_code" attribute) and use the "inspect"
module from the Python library.

If I understand you correctly, I don't think it will help you much to
inspect the byte-code. It is nearly impossible in general to conclude,
say, the return types of a function from the argument list given the
python code for the function. I doubt that there is a feasible way to
make type inference analysis on Python in a robust way since types are
a bit vague in Python.

-- 
Ulf Worsøe


On Fri, May 21, 2010 at 7:47 PM, Issyk Kol <issyk.kol at gmx.com> wrote:
> Hello.
>
> I'd like to do some ML-like type inference for Python code. I'm not trying to resurrect the static typing vs. dynamic typing debate here. It's simply that I'd need to get static typing for Python for code-generation reasons.
>
> Therefore, I'd like to ask: Does the Python C API support a way to inspect the bytecode or the source code of a given piece of Python code? What approach would be promising enough to type things in ML-way (I'm unfortunately not interested in cartesian-product type inference), and what help may the C API provide to meet this goal? (Maybe I haven't looked far enough, but I could not discern clearly what could be useful...)
>
> (Sorry for posting in non-text-mode. Using a webmail because port 25 policies in this bloody country ar sooooo restrictive.)
>
> Thanks.
>
> Issyk Kol.
> _______________________________________________
> capi-sig mailing list
> capi-sig at python.org
> http://mail.python.org/mailman/listinfo/capi-sig
>


More information about the capi-sig mailing list