[Python-ideas] Structural type checking for PEP 484
Sven R. Kunze
srkunze at mail.de
Wed Sep 16 21:45:57 CEST 2015
On 10.09.2015 20:24, Brendan Barnwell wrote:
> Right, but can't you already do that with ABCs, as in the example in
> the docs (https://docs.python.org/2/library/abc.html)? You can write
> an ABC whose __subclasshook__ does whatever hasattr checks you want
> (and, if you want, checks the type annotations too), and then you can
> use isinstance/issubclass to check if a given instance/class "provides
> the protocol" described by that ABC.
You might probably be write. Maybe, it's that this kind of "does
whatever hasattr checks you want" gets standardized via the protocol
Pondering about this idea further, current Python actually gives enough
means to do that on runtime. If I rely on method A to be present at
object b, Python will give me simply an AttributeError and that'll suffice.
So, it's only for the static typechecker again.
More information about the Python-ideas