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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4