[Python-ideas] Structural type checking for PEP 484
cory at lukasa.co.uk
Thu Sep 10 09:51:58 CEST 2015
On 9 September 2015 at 21:17, Guido van Rossum <guido at python.org> wrote:
> Jukka wrote up a proposal for structural subtyping. It's pretty good. Please
Some good feedback has been provided in this thread already, but I
want to provide an enthusiastic +1 for this change. I'm one of the
people who has been extremely lukewarm towards the Python type hints
proposal, but I believe this addresses one of my major areas of
concern. Overall the proposal seems like a graceful solution to many
of the duck typing problems.
It does not address all of them, particularly around classes that may
dynamically (but deterministically) modify themselves to satisfy the
constraints of the Protocol (e.g. by generating methods for themselves
at instantiation-time), but that's a pretty hairy use-case and there's
not much that a static type checker could do about it anyway.
Altogether this looks great (modulo a couple of small concerns raised
by others), and it's enough for me to consider using static type hints
on basically all my projects with the ongoing exception of Requests
(which has duck typing problems that this cannot solve, I think).
Great work Jukka!
More information about the Python-ideas