Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Previously, if you had to define a class method that returned an object of the class itself, adding types for it was a bit weird, it would look something like this...

To be able to say that a method returns the same type as the class itself, you had to define a TypeVar, and say that the method returns the same type T as the current class itself.

This kind of stuff is so crazy to me. I see how types are useful for defining general categories of data (int, string, float), but isn't it better to have as few types as possible? It just makes reading and using code more confusing to keep multiplying "types" like this.



"Types" beyond the basic ones, in general, are needed only when you have to define complex data structures that can hold multiple variables in one.

What Python really needs is an easy, built-in way to create mutable structs, without an overhead of creating classes. I think it's a failure of language design to miss such a useful and basic feature.

For everything else, use a function.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: