[Python-ideas] Optional Static Typing -- the Python Way

Nick Coghlan ncoghlan at gmail.com
Wed Aug 20 13:27:34 CEST 2014


On 20 Aug 2014 10:14, "Guido van Rossum" <guido at python.org> wrote:
>
> On Tue, Aug 19, 2014 at 4:02 PM, Antoine Pitrou <antoine at python.org>
wrote:
>>
>> Le 19/08/2014 18:50, Terry Reedy a écrit :
>>
>>> On 8/19/2014 9:27 AM, Nick Coghlan wrote:
>>>
>>> What I like: 'optional type hints' based on a fleshed-out ABC systems
>>> that collects all ABCs together on one module via import from current
>>> files. It seems that we have been slowly groping towards this for years.
>>
>>
>> Hmm, I've been saying this already, but my intuition is that it's a bad
idea to conflate *type descriptions* (what this proposal is about) and
actual *runtime types* (what ABCs are).
>
>
> But are they? I think the registration mechanism makes it clear that they
aren't (necessarily) runtime types -- by linking a concrete type with an
ABC through registration you are pretty clearly stating that the ABC
*describes* (an aspect of) the concrete class without automatically adding
any behavior from the ABC to it.

One of the ways I describe the explicit registration mechanism to people is
as giving you the option of lying to the interpreter. If you use explicit
registration, your registered type basically walks around with a sign
saying "I'm a duck!" and the interpreter goes "OK, you're a duck!" and
assumes it will be able to quack without actually checking in advance. It's
really just a constrained version of normal duck typing, where the
interpreter just assumes that *everything* may exhibit duck-like tendencies.

Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140820/c53cbd20/attachment.html>


More information about the Python-ideas mailing list