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

Guido van Rossum guido at python.org
Wed Jan 21 20:23:09 CET 2015


Let's discuss this idea of "exactly" further in the tracker, where I just
created an issue that touches on the same idea:
https://github.com/ambv/typehinting/issues/52

On Tue, Jan 20, 2015 at 11:31 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> 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.
>
> Stefan
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150121/08c3f501/attachment.html>


More information about the Python-ideas mailing list