[Python-ideas] Proposal: Use mypy syntax for function annotations

Brett Cannon brett at python.org
Thu Aug 14 18:01:08 CEST 2014


On Thu Aug 14 2014 at 10:53:37 AM Petr Viktorin <encukou at gmail.com> wrote:

> It seems to me that rather than adding a module which is only used by
> one project so far to the standard library is a bit premature.
>
> I support optional typing, but why push this to stdlib now? Wouldn't
> it be better to wait until most IDEs/linters all agree on this syntax,
> until freezing it in stdlib? So far typing seems to be a part of mypy,
> shouldn't it spend some time on PyPI first?
>

Because as you have noticed in this thread there are already a ton of
competing solutions and no consensus has been reached. Sometimes Guido
and/or python-dev have to step in and simply say "there is obvious need and
the community is not reaching consensus, so we will make the decision
ourselves".


>
> I'm also sure about there not being other uses of annotations -- clize
> aside, there are not many widely used Python3-only 3rd party
> libraries, so it's no surprise that nothing big is built around Python
> 3 features.
>
> Maybe the way from PEP 3107's "here's a feature, use it for whatever
> you like" to "annotations are for typing declarations, using
> mypy/typing syntax" should include a step of "if you use annotations
> for typing, use mypy/typing syntax for it". (And perhaps it should end
> there.)
>

That's a possibility. Another thing to support this approach is that if
something like List[str] is used over `[str]`  then the returned object can
subclass some common superclass which can be typechecked for to know that
the annotation is from typing.py and not clize/scription and continue to
function. That way you can avoid any decorators adding some attribute on
functions to know that types have been specified while allowing function
annotations to be used for anything. Otherwise a @typing.ignore decorator
could also exist for alternative formats to use (since typing has been the
most common use case and decorating your single main() function with
@typing.ignore is not exactly heavy-handed).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140814/288aede0/attachment.html>


More information about the Python-ideas mailing list