[Python-ideas] PEP 484 (Type Hints) -- first draft round

Stefan Behnel stefan_ml at behnel.de
Wed Jan 21 08:31:03 CET 2015

Guido van Rossum schrieb am 19.01.2015 um 04:40:
> On Sun, Jan 18, 2015 at 12:36 PM, Stefan Behnel wrote:
>> would be nice to at least be able to explicitly express somehow that
>> subtypes should be disallowed.
> Can you come up with a specific proposal? Maybe we're not as far apart as
> we think. :-)

Normally, "x: List[int]" would mean that x is either a list or a subtype of
list, where each item is an int or a subtype. To disallow subtypes, you
could have something like "exactly(List)[int]" or "List[exactly(int)]" or
"exactly(List[int])", which would then make it clear that the exact type
matters, only for the List in the first case, only for the item type in the
second, and (this is not necessarily required) for all types inside of the
"exactly()" call in the last case. The return value of "exactly()" could be
some kind of type wrapper object which marks the wrapped type construct as
allowing "no subtypes".

This would keep the normal case of allowing subtypes everywhere normal and
simple, but would allow restricting the type to disallow subtypes in the
cases where it seems appropriate.


More information about the Python-ideas mailing list