[Python-ideas] Lessons from typing hinting Whoosh (PEP484)

Vito De Tullio vito.detullio at gmail.com
Mon Nov 16 01:51:02 EST 2015


Matt Chaput wrote:

> 2. It would be really nice if we could have "type aliasing" (or whatever
> it's called). I have a lot of types that are just something like
> "Tuple[int, int]", so type checking doesn't help much. It would be much
> more useful if I have a value that Python sees as (e.g.) an int, but have
> the type system track it as something more specific. Something like this:
> 
>     DocId = typing.TypeAlias(int)
>     DocLength = typing.TypeAlias(int)
> 
>     def id_and_length() -> Tuple[DocId, Length]:
>         docid = 5  # type: DocId
>         length = 10  # type: Length
>         return docid, length

like... type aliases? https://www.python.org/dev/peps/pep-0484/#type-aliases

-- 
By ZeD



More information about the Python-ideas mailing list