[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484

Brett Cannon brett at python.org
Sat Aug 6 13:41:11 EDT 2016


On Fri, 5 Aug 2016 at 15:27 Eric Snow <ericsnowcurrently at gmail.com> wrote:

> On Fri, Aug 5, 2016 at 10:41 AM, Guido van Rossum <guido at python.org>
> wrote:
> > On Fri, Aug 5, 2016 at 9:23 AM, Eric Snow <ericsnowcurrently at gmail.com>
> wrote:
> >> The only thing I'd like considered further is exposing the annotations
> >> at runtime.
> >
> > Actually my current leaning is as follows:
> > [snip]
>
> Sounds good.  I don't think it's likely to be a problem for code that
> expects __annotations__ only on functions (if such code exists).
>
> > I considered that, but before allowing that complexity, I think we
> > should come up with a compelling use case (not a toy example).
>
> Agreed.
>
> > [snip]
> >> We should still keep this possible future aspect in mind though.
> >
> > The problem with such a promise is that it has no teeth, until the
> > future behavior is entirely specified, and then we might as well do it
> > now. My current proposal (no evaluation of annotations for locals)
> > means that you can write complete nonsense there (as long as it is
> > *syntactically* correct) and Python would allow it. Surely somebody is
> > going to come up with a trick to rely on that and then the future
> > development would break their code.
>
> Yeah, I think your current approach is good enough.
>
> >> Relatedly, it would be nice to address the future use of this syntax
> >> for more generic variable annotations (a la function annotations), but
> >> that's less of a concern for me.  The only catch is that making
> >> "class" an optional part of the syntax impacts the semantics of the
> >> more generic "variable annotations".  However, I don't see "class" as
> >> a problem, particularly if it is more strongly associated with the
> >> name rather than the annotation, as you've suggested below.  If
> >> anything it's an argument *for* your recommendation. :)
> >
> > I'm unclear on what you mean by "more generic variable annotations".
> > Do you have an example?
>
> I'm talking about the idea of using variable annotations for more than
> just type declarations, just as there are multiple uses in the wild
> for function annotations.  As I said, I'm not terribly interested in
> the use case and just wanted to point it out. :)
>

Since the information will be in the AST, it would be a more generic
solution to come up with a way to keep the AST that was used to generate a
code object around. I'm not saying that this is a specific reason to try
and tackle that idea (although it does come up regularly), but I think it's
a reasonable thing to punt on if this is a better all-around solution in
this case.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160806/a305db53/attachment.html>


More information about the Python-ideas mailing list