[Python-ideas] Proposal: Use mypy syntax for function annotations
Ryan Hiebert
ryan at ryanhiebert.com
Fri Aug 15 05:33:24 CEST 2014
> On Aug 14, 2014, at 2:02 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>
> Would it be possible, and desirable, to modify the built-in types so
> that we could re-use them in the type annotations?
>
> def word_count(input: list[str]) -> dict[str, int]:
>
>
> Since types are otherwise unlikely to be indexable like that, I think
> that might work.
Huge +1 from me. I know that extending types to do more might not be the first thing someone would want to do, but I think describing types well is exactly the right thing to extend type instances to do.
If that were to be considered plausible, it would also make sense to my mind to implement the union operator (|) on types, so that we could use:
int | None
Which I think would be quite beautiful. (or would it need to be NoneType? Perhaps we can give some special consideration to the None singleton)
It’s only tangentially related, but my (likely broken) work on a TypeSet metaclass might also be informative. It’s goal was to bring set operations to types, which has some overlap with the above discussion.
https://github.com/ryanhiebert/typeset
More information about the Python-ideas
mailing list