On Thu, Jul 19, 2018 at 10:07 AM, Stephan Houben <stephanh42@gmail.com> wrote:
You are aware of numba?


Stephan

Op do 19 jul. 2018 16:03 schreef Eric Fahlgren <ericfahlgren@gmail.com>:
On Thu, Jul 19, 2018 at 6:52 AM Michael Hall <python-ideas@michaelhall.tech> wrote:
While I am aware of projects like Cython and mypy, it seems to make sense for CPython to allow optional enforcement of type hints, with compiler optimizations related to it to be used. While this would not receive the same level of performance benefits as using ctypes directly, there do appear to be various gains available here.

​Just to make sure I understand:  In other words, they would no longer be "hints" but "guarantees".  This would allow an optimizer pass much greater latitude in code generation, somehow or other.​

For purposes of illustration (this is not a proposal, just for clarification):

@guaranteed_types
def my_sqrt(x:c_double) -> c_double:
    ...

would tell the compiler that it's now possible to replace the general PyObject marshalling of this function with a pure-C one that only accepts doubles and woe be unto those who use it otherwise.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Less so than I probably should have been given the idea I'm pitching. I've given it a quick look, and at a glance, it seems to already be capable of the desired behavior specifically centered around performance. I do still think it may be beneficial to have in the CPython reference implementation alongside a standard grammar, which could further enable the various libraries and python implementations to make use of the additional knowledge that the type hint is intended as a more than a hint.