[Python-ideas] Type Hinting Kick-off

Nick Coghlan ncoghlan at gmail.com
Mon Dec 22 06:35:24 CET 2014


On 22 December 2014 at 14:05, Guido van Rossum <guido at python.org> wrote:

> I would really like to wait and see how this plays out -- the proposal I'm
> working on is careful not to have any effect at runtime (as long as the
> typing.py module can be imported and as long as the annotation expressions
> don't raise exceptions), and use of a static checker is entirely optional
> and voluntary.
>

Agreed - I see this as a good, incremental evolution from the increased
formality and flexibility in the type system that was introduced with ABCs,
and I think that's been successful in letting folks largely not need to
worry about them unless they actually need to deal with the problems they
solve (like figuring out whether a container is a Sequence or Mapping).

Ideally we'll get the same result here - folks that have problems where
type annotations can help will benefit, while those that don't need them
won't need to worry about them.


> Perhaps the PEP should define some way to tell the type checker not to
> follow certain imports? That would be useful in case you have a program
> that tries to follow the annotation conventions for static checking but
> imports some library that uses annotations for a different purpose. You can
> probably do this already for mypy by writing a stub module.
>

For inline use, it may be worth defining a module level equivalent to
pylint's "#pylint: skip-file" comments (rather than having each static
checker come up with its own way of spelling that). Aside from that, it may
also be worth recommending that static type checkers provide clear ways to
control the scope of scanning (e.g. by allowing particular directories and
files to be excluded, or limit scans to particular directories.

In both cases, the PEP would likely need to define the implied annotations
to be assumed for excluded modules. I realised in trying to write this
email that I don't currently understand the consequences of not having
annotation data available for a module in terms of the ripple effects that
may have on what scanners can check - from the end user perspective, I
believe that's something I'd need to know, even though I wouldn't
necessarily need to know *why* those were the default assumptions for
unannotated operations. (I'm curious about the latter from a language
*design* perspective, but I think I'd be able to use the feature
effectively just by knowing the practical consequences without necessarily
understanding the theory)

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141222/c67e5d2d/attachment.html>


More information about the Python-ideas mailing list