[Python-Dev] PEP 484 syntax: NONONONONONONO! (original) (raw)
Chris Angelico rosuav at gmail.com
Sun Feb 1 21:54:51 CET 2015
- Previous message: [Python-Dev] PEP 484 syntax: NONONONONONONO!
- Next message: [Python-Dev] Workflow PEP proposals are now closed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Feb 1, 2015 at 9:13 PM, Benjamin <deisum at 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
- Previous message: [Python-Dev] PEP 484 syntax: NONONONONONONO!
- Next message: [Python-Dev] Workflow PEP proposals are now closed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]