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

Chris Angelico rosuav at gmail.com
Mon Nov 16 10:53:31 EST 2015


On Tue, Nov 17, 2015 at 2:48 AM, Matt Chaput <matt at whoosh.ca> wrote:
> As I read it, that's just a way to avoid having to spell out the same type definition more than once. It's not the same as being able to define a new type for the type system which Python sees as a plain old primitive type.
>
> I'm probably not using the right programming language theory word for this concept :)

I'm not entirely sure, but I think you might be able to subclass
something to create a special form. A length might be a subclass of
integer, and a docid could be a different subclass of integer. Lengths
and document IDs could then be counted as distinct from each other,
although any function that expects an integer would happily accept
either. (That might not be appropriate for docid, but it would for
length (eg range() should accept them), so you might want to do docid
some other way.)

ChrisA


More information about the Python-ideas mailing list