[Python-ideas] Proposal: Use mypy syntax for function annotations
willvarfar at gmail.com
willvarfar at gmail.com
Sun Aug 17 12:13:24 CEST 2014
When discussed on reddit programming ("proggit" as its called), there were
plenty of people saying they really didn't like the mypy syntax:
http://www.reddit.com/r/programming/comments/2disob/proposal_for_python_type_annotations_from_guido/
(Declaration: I am the author of obiwan https://pypi.python.org/pypi/obiwan
and I got a lot of upvotes on that proggit thread when I promoted the
obiwan style instead)
On 14 Aug 2014 13:16, "willvarfar at gmail.com" <willvarfar at gmail.com> wrote:
> I fully support formalizing Python 3's annotations for type checking.
>
> I wrote - and use daily - my own type checker called obiwan
> https://pypi.python.org/pypi/obiwan
>
> Its a runtime type checker, and if enabled will check and enforce
> types on every call.
>
> I support the wider adoption and standardization of static type
> checkers, but runtime checkers are still wanted for very dynamic code
> and for checking external data e.g. I use obiwan for validating JSON.
>
> One small detail is that I feel the obiwan annotations are more
> pythonic than the mypy examples given.
>
> E.g. instead of:
>
> from typing import List, Dict
>
> def word_count(input: List[str]) -> Dict[str, int]:
> ...
>
> It would be:
>
> def word_count(input: [str]) -> {str, int}:
> ...
>
> Obiwan does not check types within functions; I was unwilling to try
> and overload comments! You can invoke obiwan to check things
> explicitly, but these are more as assertions.
>
> Anyway, when I look at the mypy in-function annotations (where
> comments are overloaded) I am cautious. It would be far nicer if we
> had annotations as part of the language instead, e.g. instead of:
>
> result = {} #type: Dict[str, int]
>
> It would be:
>
> result = {} -> {str, int}
>
> where we use the -> arrow again. I can see pros and cons for any
> implementation (as we'd want the annotation to be both to declare a
> type and to check a type, and want the annotation to be attached to
> the variable forever etc) so this would need a full PEP treatment and
> possibly be configurable as asserts are.
>
> But proper annotation support in the language rather than overloading
> comments would definitely be my preference.
>
> /Will
>
> /Will
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140817/163463e9/attachment.html>
More information about the Python-ideas
mailing list