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

Juancarlo Añez apalala at gmail.com
Fri Jan 23 01:55:11 CET 2015


On Thu, Jan 22, 2015 at 3:35 PM, Guido van Rossum <guido at python.org> wrote:

> The only situation where there may be a desire to change something (the
> minimal thing being to add a "# type: OFF" comment at the top of a module)
> is when a library that uses annotations for non-type-hinting purposes is
> used by an application (or another library) that wants to use type hints,
> and the user who is running the type checker cannot live with the noise
> output spewed by the type checker for that library.
>
> Even there, the problem could also be solved by having a way to configure
> the type checker to ignore annotations in certain packages (or to only
> check code in specific directories).
>

Having library authors change their code because type hinting was
introduced would be unacceptable.

The burden must all on whomever wants to benefit from type checking.


>
>
>> Since type hints already depend on the 'typing' module anyway, what
>> exactly would be wrong with the type checker defaulting off unless it is
>> imported?
>>
>
> I've considered that, but I find it limiting. It is quite likely that a
> module can be fully annotated with type hints without ever needing to
> reference the typing module. For example, all argument types may be simple
> built-in types (strings and numbers) or user-defined classes. I think it
> would be unexpected if type hints that were present in a module would be
> ignored by the type checker unless the typing module was imported. (Also,
> perhaps ironically, most linters will complain about modules that are
> imported but not used. :-)
>

"import typing" is a nice and easy compromise, very much in the pythonic
way, in my opinion.

If you want your module type checked: import typing. It will not be checked
otherwise.

It's simple, backwards compatible, very little effort for those wanting to
jump into PEP484, and zero pain for those who don't.

Cheers,

-- 
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150122/4ac9cf7d/attachment.html>


More information about the Python-ideas mailing list