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

Ethan Furman ethan at stoneleaf.us
Thu Aug 14 22:51:53 CEST 2014


On 08/14/2014 01:33 PM, Cory Benfield wrote:
> On 14 August 2014 19:52, Steven D'Aprano 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 are bad assumptions, since the PEP is about defining how annotations are to be used and specifically states there 
will be *no run-time checking*.  To be of use at all you have to get a third-party program (mypy at this point) and use it.

So the scenario you list simply isn't going to happen... at least, not like that.

What could happen is newbie team member tries to check something in, but mypy and annotations are in the pre-check, 
no-one has told newbie team member about mypy or newbie forgot and is too embarrassed to go ask someone, so same basic 
problem arises.

That, however, is mostly outside the concerns of developing Python.

--
~Ethan~


More information about the Python-ideas mailing list