| Store | Cart

Re: [Python-Dev] PEP 484 syntax: NONONONONONONO!

From: Chris Angelico <ros...@gmail.com>
Mon, 2 Feb 2015 07:54:51 +1100
On Sun, Feb 1, 2015 at 9:13 PM, Benjamin <dei...@gmail.com> wrote:
> I much prefer the idea of a 'where' keyword to denote typing, as discussed> http://aroberge.blogspot.com/2015/01/type-hinting-in-python-focus-on.html,> but I think a refinement of their idea would prove even better:>> def retry(callback, timeout, retries=None) where> ........callback is Callable[AnyArgs, Any[int, None]],> ........timeout is Any[int, None],> ........retries is in [int, None], # 'is in' construct is more readable,> dunno about complexity> ........return is None:> ....pass

Massively verbose, and requires duplication of your argument names. If
you're going to have the args all listed down below, the first line is
redundant; all you need to do is incorporate the "=None" default into
the lower part, and you can drop the first line altogether.

def retry(
    callback: Callable[AnyArgs, Optional[int]],
    timeout: Optional[int],
    retries:Optional[int]=None
) -> None:
    pass

Indent that any way you like. Apart from taking advantage of
Optional[] rather than explicitly Anying with None, that's a direct
translation from your code to actual annotations. Advantage: It works
in current code, as long as you backport those names (which typing.py
will do). I'm stating the parameter names exactly once each, I'm
laying it out pretty much the same way you had it, and there's no need
to add any more syntax beyond PEP 3107.

ChrisA
_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Benjamin Feb 01, 2015 10:13 am
Mark Lawrence Feb 01, 2015 03:59 pm
Chris Angelico Feb 01, 2015 08:54 pm
Messages in this thread