[Python-ideas] Type Hinting Kick-off

Guido van Rossum guido at python.org
Tue Dec 23 01:59:33 CET 2014


On Mon, Dec 22, 2014 at 3:54 AM, Petr Viktorin <encukou at gmail.com> wrote:
>
> On Mon, Dec 22, 2014 at 8:02 AM, Guido van Rossum <guido at python.org>
> wrote:
> [...]
> > limits -- e.g. repr() of Any is still a string, and Any==Any is still a
> > bool.
>
> Why is Any==Any a bool?
> Comparison operators can return anything, and libraries like Numpy or
> SQLAlchemy take advantage of this (comparing Numpy arrays results in
> an array of bools, and comparing a SQLAlchemy Column to something
> results in a comparison expression, e.g. `query.filter(table.id ==
> 2)`). Would type checkers be expected to reject these uses?
>

Never mind, I forgot about that. :-)

>
> From Pragmatics section in the article:
> > If a default of None is specified, the type is implicitly optional, e.g.
> >     def get(key: KT, default: VT = None) -> VT: ...
>
> Why is this limited to None? Can this be extended to "if there's a
> default argument, then that exact object is also allowed"? That would
> allow things like:
>
>     _MISSING = object()
>     def getattr(key: str, default: VT=_MISSING) -> VT: ...
>

Well, that would require the type checker to be smarter. I don't want to go
down the slippery path of defining compile-time expressions. Allowing None
is easy (it's a keyword), useful and covers the common cases.

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


More information about the Python-ideas mailing list