1. 23

  2. 11

    Nice project, it’s definitely something I’ve wanted before. That being said, as the article mentions, this is mostly present in the standard library as “singledispatch”. But “classes” adds mypy support, which is really useful. But, it looks like mypy will be adding a plugin for singledispatch this summer: https://github.com/mypyc/mypyc/issues/802 so maybe the two libraries can merge together: https://github.com/dry-python/classes/issues/242

    Also, one thing to remember is that you can always just “manually” encode the typeclass, by passing around an object like “Greeter[T]” whose methods support calling “greet” on T. So then to call greet on a str, you’d need a “Greeter[str]” object in addition to a “str”. This can work really well in many situations; for example, I use it here: https://github.com/catern/rsyscall/blob/master/python/rsyscall/struct.py#L10

    1. 1

      Python really just needs to support dynamic typing at this point. Duck typing and the corresponding ecosystem that’s emerged just to do basic type system work is kind of a circus.

      1. 4

        Don’t you mean “static typing”? Python is a strongly typed, but dynamically typed language.

        Anyway, Python’s never going to have compulsory static typing. Gradual static typing, sure, but it’s never going to be compulsory.