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

Steven D'Aprano steve at pearwood.info
Tue Jan 12 21:17:57 EST 2016


On Mon, Jan 11, 2016 at 08:38:59PM -0800, Guido van Rossum wrote:
> On Mon, Jan 11, 2016 at 5:39 PM, Steven D'Aprano <steve at pearwood.info>
> wrote:
> 
> > On Mon, Jan 11, 2016 at 12:22:55PM -0800, Andrew Barnert via Python-ideas
> > wrote:
> >
> > > 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.
> >
> > I would be happy to see a runtime switch similar to -O that drops
> > annotations in 3.x, similar to how -OO drops docstrings.
> 
> 
> Actually my experience with -OO (and even -O) suggest that that's not a
> great model (e.g. it can't work with libraries like PLY that inspect
> docstrings). A better model might be to let people select this on a per
> module basis. Though I could also see a future where __annotations__ is a
> more space-efficient data structure than dict.
> 
> Have you already run into a situation where __annotations__ takes up too
> much space?

No at such, but it does seem an obvious and low-impact place to save 
some memory. Like doc strings, they're rarely used at runtime outside of 
the interactive interpreter.

But your suggestion sounds more useful.


-- 
Steve


More information about the Python-ideas mailing list