[Python-ideas] PEP 484 (Type Hints) -- first draft round

Guido van Rossum guido at python.org
Fri Jan 16 21:08:05 CET 2015


Yes, the PEP tries to gently push an agenda where annotations are only used
for Python type hints. Note that this was the original idea when PEP 3107
was created, even if it doesn't say so.

Jim Baker from the Jython team is totally on board with the proposal, he
just wants to have a way to declare that e.g. java.Util.ArrayList is
equivalent to typing.List. This can be done through a stub file. Read
https://github.com/ambv/typehinting/issues/7 for details. Also note that
Jim co-write a paper on the use of gradual typing for Jython, referenced in
PEP 482 (the literature overview) -- see
https://www.python.org/dev/peps/pep-0482/#reticulated-python.

I don't know what to answer for Cython -- doesn't it have its own syntax
for declaring C types? Or is it now also using annotations? If Cython uses
annotations with different meanings, perhaps for Cython files the Python
annotations could be put in stub files. Stub files take precedence over
regular modules when the static checker runs. (Note that the PEP doesn't
yet describe stubs, simply because we ran out of time this week to write it
up. They are implemented by mypy. See
https://github.com/ambv/typehinting/issues/22 .

On Fri, Jan 16, 2015 at 11:56 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> Guido van Rossum schrieb am 16.01.2015 um 20:45:
> > On Fri, Jan 16, 2015 at 11:38 AM, Stefan Behnel wrote:
> >
> >> Guido van Rossum schrieb am 16.01.2015 um 18:17:
> >>> After a long editing process we've got PEP 484
> >>> <https://www.python.org/dev/peps/pep-0484/> (Type Hints) ready for
> your
> >>> review.
> >>
> >> I can't see it mention interoperability with other usages of function
> >> annotations. I think the idea was that in this case, the type hints
> must be
> >> explicitly declared as such, e.g.
> >>
> >>     def func(x: {'type': str, 'wobble': 'off',
> >>                  'ctype': 'std::string[utf8]'}) ->
> >>                                   {'type': str, 'wobble': 'sure'}:
> >>         return x + 'huhu'
> >
> > That's discussed in this section:
> >
> https://www.python.org/dev/peps/pep-0484/#compatibility-with-other-uses-of-function-annotations
> > . The dict notation (which was proposed in an earlier thread on
> > python-ideas) looks too messy to seriously support.
>
> So, what you're saying is: either Python type hints are used exclusively,
> and no other annotations, or the user must add magic comments in all places
> where annotations are used, so that each tool that processes a subset of
> them knows which to process and which to ignore. And mixing them in one
> function will still be completely impossible.
>
> I don't see how that's less messy than explicit naming of the type of
> annotation. It's just less generally usable.
>
> Also, how would you support different type systems, such as C/C++ in Cython
> or Java types in Jython? In both cases, "int" or "float" would mean
> something different than the Python types "int" and "float", for example.
>
> Stefan
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150116/b657680c/attachment.html>


More information about the Python-ideas mailing list