[Python-Dev] PEP 563: Postponed Evaluation of Annotations
Guido van Rossum
guido at python.org
Fri Nov 3 10:40:48 EDT 2017
IMO the inability of referencing class-level definitions from annotations
on methods pretty much kills this idea.
On Thu, Nov 2, 2017 at 11:27 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 3 November 2017 at 04:39, Jukka Lehtosalo <jlehtosalo at gmail.com> wrote:
> >> > * forward references: when a type hint contains names that have not
> >> > defined yet, that definition needs to be expressed as a string
> >> > literal;
> >> After all the discussion, I still don't see why this is an issue.
> >> Strings makes perfectly fine forward references. What is the problem
> >> that needs solving? Is this about people not wanting to type the leading
> >> and trailing ' around forward references?
> > Let's make a thought experiment. What if every forward reference would
> > require special quoting? Would Python programmers be happy with this?
> > let's use ! as a suffix to mark a forward reference. They make perfectly
> > fine forward references. They are visually pretty unobtrusive (I'm not
> > suggesting $ or other ugly perlisms):
> > def main():
> > args = parse_args!() # A forward reference
> > do_stuff!(args) # Explicit is better than implicit
> > def parse_args():
> > ...
> > def do_stuff(args):
> > ...
> > Of course, I'm not seriously proposing this, but this highlights the fact
> > that in normal code forward references "just work" (at least usually),
> > if we'd require a special quoting mechanism to use them anywhere, Python
> > would look uglier and more inconsistent. Nobody would be happy with this
> > change, even though you'd only have to type a single ! character extra --
> > that's not a lot work, right?
> > I think that the analogy is reasonable.
> I think it also makes a pretty decent argument that pushing function
> annotations into implicit lambda expressions will be easier to explain
> to people than converting them into strings, and then having to
> explain an entirely new complex set of name resolution rules.
> Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev