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

Bob Ippolito bob at redivi.com
Thu Aug 14 22:54:20 CEST 2014


On Thu, Aug 14, 2014 at 1:33 PM, Cory Benfield <cory at lukasa.co.uk> wrote:

> On 14 August 2014 19:52, Steven D'Aprano <steve at pearwood.info> wrote:
> > I want to pass a Decimal to foo(). All I have to do is *not* install
> > mypy, or disable it, and lo and behold, like magic, the type checking
> > doesn't happen, and foo() operates by duck-typing just like in the glory
> > days of Python 1.5. Both Fred and I are now happy, and with the explicit
> > isinstance check removed, the only type checking that occurs when I run
> > Fred's library are the run-time duck-typing checks.
>
> Thanks for explaining Steven, that's a lot clearer. I understand where
> you're coming from now.
>
> I still don't agree, however. I suspect what's more likely to happen
> is that Fred writes his code, a user goes to run it with duck typing,
> and it breaks. Assuming the static checker is in CPython and on by
> default, there are a number of options here, most of which are bad:
>

These assumptions are incorrect.

* Adding the checker to CPython is not part of this proposal.
* Turning it on by default is not part of this proposal.
* Having the type checker in any way associated with the runtime is not
part of this proposal.

What is part of this proposal?

* An effort to standardize on a particular syntax for optional type
annotations using Python 3 function annotations
* The syntax will be handwavingly based on what's in mypy, and thus implies
some semantics but not the implementation of the type checker/inference/etc.
* A suggestion to use tools such as mypy to provide a static type checking
pass in much the same way that people use linters today
* A suggestion that IDEs, documentation tools, etc. take advantage of the
information provided by the type annotations
* Deprecation of using function annotations for any other purpose. They
can't really be composed, and ideally type checkers can work primarily at
the syntax level and not have to evaluate the module with a full Python
interpreter in order to extract the annotations, so it's best to keep the
syntax uniform.


> I am not averse to having static checking be an option for Python and
> for annotations to be the mechanism by which such typing is done. I
> just think we should be really cautious about ever including it in
> CPython.


So, it sounds like you're not averse to what is has been proposed. :)

-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140814/40e77b5c/attachment-0001.html>


More information about the Python-ideas mailing list