[Python-ideas] "Sum" Type hinting [was: Type hinting for path-related functions]

Greg Ewing greg.ewing at canterbury.ac.nz
Thu May 19 19:33:06 EDT 2016


Guido van Rossum wrote:
> I'm still not sure I understand why this check that you've handled all
> cases is so important (I've met a few people who obsessed about it in
> other languages, but I don't really feel the need in my gut yet).

If you're programming in the usual OO style, then when you
add a new subclass, most of the code needed to support it goes
into that class. You can easily go through all the methods
of the base class and make sure you've overridden the
ones you need to.

But if you add a new branch to an algebraic type, you need
to chase down all the pieces of code scattered about your
program that operate on that type and update them.

If you're happy to rely on testing to do so, that's fine.
But if you're a static checking kind of person, I can see
the attraction of having some help from your tools for it.

> I also don't think that subclasses cause problems (if there's a match
> for a particular class, it will match the subclass too).

It's not subclassing an existing branch that's the problem,
it's adding a new branch to the union.

-- 
Greg


More information about the Python-ideas mailing list