[Python-ideas] Proposal: Use mypy syntax for function annotations
Oleg Broytman
phd at phdru.name
Thu Aug 14 21:23:34 CEST 2014
On Fri, Aug 15, 2014 at 04:52:45AM +1000, Steven D'Aprano <steve at pearwood.info> wrote:
> But with this proposal, Fred may write his function like this:
>
> def foo(x:float)->float:
> return (x+1)/2
>
> and rely on mypy to check the types at compile time. Fred is happy: he
> has static type checks, Python does it automatically for him (once he
> has set up his build system to call mypy), and he is now convinced that
> foo() is type-safe and an isinstance check at run-time would be a waste
> of cycles.
>
> 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.
Well, that's funny. Static type checking as a way to subvert type
checking! (-:
Oleg.
--
Oleg Broytman http://phdru.name/ phd at phdru.name
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-ideas
mailing list