bpo-32227: functools.singledispatch supports registering via type annotations by ambv · Pull Request #4733 · python/cpython (original) (raw)

This is not quite right.

Historically the syntactic feature of annotations didn't have a standardized meaning, so the standard library couldn't use it internally and we couldn't document any APIs that would use it. Otherwise we'd be creating a "de facto" standard.

The situation changed with PEP 484. Since this was a very large feature, we have taken the stance that we won't be covering the standard library with type hints, at least not until typing graduates from provisional status and further discussion on python-dev (or maybe even a PEP about this).

However, at this point we never said we wouldn't allow for the standard library to implement features that allow the users of the library to utilize annotations. The typing module itself is an obvious example: it presents users with a feature that requires using the syntactic construct of annotations.
Data classes for Python 3.7 also utilize annotations to define fields. And in this pull request, singledispatch uses annotations for a similar purpose: to inform runtime type decisions.

And by the way, since the entire point of PEP 557 was to bring an "attrs" implementation to the standard library in order for the standard library to be able to use it itself, I think with Python 3.7 effectively type annotations are going to start appearing in the standard library by means of data classes alone. At least with singledispatch I'm leaving the classic syntax alone so users with a visceral reaction to annotations can keep using it.