PEP 484 syntax: NONONONONONONO!

The proposed syntax is abominable. It's the opposite of readable. The function annotation syntax is ugly, but potentially useful for things like documentation. While it may very well have been created with the idea of type-checking, actually using it for such quickly turns into an unreadable morass of information that is far more difficult for human brains to parse, which makes this usage the antithesis of pythonic. 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 def greeting(name) where name is str, return is str: ....return 'Hello ' + name x, y = [], [] where x, y is List[Employee], List[Manager] To me, this orders of magnitude more readable than the proposed nonsense. PS. Obviously the 8-space indent above would only a convention, not requirement.

On 01/02/2015 10:13, Benjamin wrote:
The proposed syntax is abominable. It's the opposite of readable.
I have no views on the subject as I won't be using it, but there is no need to shout to get your point across. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence

On Sun, Feb 1, 2015 at 9:13 PM, Benjamin <deisum@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
participants (3)
-
Benjamin
-
Chris Angelico
-
Mark Lawrence