[Python-ideas] Type Hinting Kick-off

Petr Viktorin encukou at gmail.com
Mon Dec 22 12:54:04 CET 2014

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?

>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: ...

More information about the Python-ideas mailing list