[Python-ideas] Proposal to extend PEP 484 (gradual typing) to support Python 2.7

Andrew Barnert abarnert at yahoo.com
Mon Jan 11 15:22:55 EST 2016


On Jan 11, 2016, at 10:42, Gregory P. Smith <greg at krypto.org> wrote:
> 
> The goal of the # type: comments as described is to have this information for offline analysis of code, not to make it available at run time.  Yes, a decorator syntax could be adopted if anyone needs that. I don't expect anyone does. Decorators and attributes would add run time cpu and memory overhead whether the information was going to be used at runtime or not (likely not; nobody is likely to deploy code that looks at __annotations__).

These same arguments were made against PEP 484 in the first place, and (I think rightly) dismissed.

3.x code with annotations incurs a memory overhead, even though most runtime code is never going to use them. That was considered to be acceptable. So why isn't it acceptable for the same code before it's ported to 3.x? Or, conversely, if it isn't acceptable in 2.x, why isn't it a serious blocking regression that, once the port is completed and you're running under 3.x, you're now wasting memory for those useless annotations?

Meanwhile, when _are_ annotations useful at runtime? Mostly during the kind of debugging that you'll be doing during something like a port from 2.x to 3.x. While you're still, by necessity, running under 2.x. If they're not useful there, it's hard to imagine why they'd be useful after the port is done, when you're deploying your 3.x code.

So it seems like using decorators (or backporting the syntax, as Google has done) has better be acceptable for 2.7, or the PEP 484 design has a serious problem, and in a few months we're going to see Dropbox and Google and everyone else demanding a way to use type hinting without wasting memory on annotations are runtime in 3.x.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160111/eb851609/attachment.html>


More information about the Python-ideas mailing list