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

Stefan Behnel stefan_ml at behnel.de
Fri Jan 16 20:56:47 CET 2015

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.


More information about the Python-ideas mailing list