[Python-ideas] Add an option that allow check Type Hints in runtime

Ma Lin animalize81 at hotmail.com
Fri Jul 8 04:19:41 EDT 2016

I forget to add python-ideas at python.org<mailto:python-ideas at python.org> in CC, let me retell to the others:

I mean real check by the interpreter, not an '__annotations__' attribute.
And I just had a look, mypy is a static checker, without actually running the code.

My thought is modifying CALL_FUNCTION and RETURN_VALUE of the interpreter, so that allow them to check in each function calling when option enalbed.

Cite a case:

def fun(a: str, b: int) -> int:
    return len(a) + b
fun('arg1', 'arg2')

Whit the option and run this code, the interpreter will give an error prompt:
    Type of argument b is wrong. (or something like this)

This is very useful for development and debugging.

Without the option, the interpreter just ignores Type Hints in runtime, so no performance lose in project's final deploy.

IMO, this will maximize the benefit of Type Hints within a small cost.

在 7-8 周五 14:42, David Mertz 写道:

This exists already. All the annotations love on the '__annotations__' attribute is a function or method. Check that at runtime however you like!

On Jul 7, 2016 11:39 PM, "Ma Lin" <animalize81 at hotmail.com<mailto:animalize81 at hotmail.com>> wrote:
Hi, all,

     Is it possible to add an option that allow check Type Hints in
     So that I can enable dynamic type checking when debugging. And
disable it in final deploy, no performance lose.

Python-ideas mailing list
Python-ideas at python.org<mailto:Python-ideas at python.org>
Code of Conduct: http://python.org/psf/codeofconduct/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160708/c96f26c5/attachment-0001.html>

More information about the Python-ideas mailing list