[Python-ideas] Runtime types vs static types
steve at pearwood.info
Sun Jul 2 07:57:33 EDT 2017
On Sun, Jul 02, 2017 at 09:38:11PM +1000, Chris Angelico wrote:
> On Sun, Jul 2, 2017 at 9:16 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> > If we want to support that optimization, we could add an optimization
> > flag that strips annotations at runtime, just as the -OO flag strips
> > docstrings. That becomes a matter of *consenting adults* -- if you don't
> > want annotations, you don't need to keep them, but it then becomes your
> > responsibility that you don't try to use them. (If you do, you'll get a
> > runtime AttributeError.)
> IMO people should act as if this will eventually be the case.
> Annotations should be evaluated solely for the purpose of populating
> __annotations__, and not for any sort of side effects - just like with
Avoiding side-effects is generally a good idea, but I think that's
probably taking it too far.
I think that we should assume that
will always look up and call Spam when the function is defined. But we
should be prepared that
might not exist, if we're running in a highly-optimized mode, or
MicroPython, or similar.
More information about the Python-ideas