Associated Types #2884
Replies: 1 comment
-
This discussion would probably be more appropriate for the python/typing github repo. If your intent is to propose an extension to the Python type system like higher-kinded types, that would be the place where it should be discussed first. There have been some discussions of adding higher-kinded types to the Python type system, but those discussions haven't gone very far. My personal viewpoint is that they might be a good thing to add at some point, but now doesn't seem like the right time. IMO, there are many other higher-priority pain points that should be addressed in Python typing before the Python typing community focuses their attention on something more esoteric like higher-kinded types. An alternative approach that might work within the bounds of the current type system in your case is to use structural subtyping. Define a generic protocol that defines the interface expected for |
Beta Was this translation helpful? Give feedback.
-
Hello.
First off, I'm not entirely sure if this is the most appropriate place to start this kind of discussion, please redirect me if it is not.
So I tried to add static typings to my Python library but I ditched the project after writing multiple
TypeVars
for the same types. The pattern in my code looked a little something like this:This is fine, but what if we want to create a wrapper for the types?
Now the API is a bit weird. If we had associated types we could keep all of the type definitions in the implementation class:
What do you think? Something like this would make my code a lot easier to manage. Rust's explanation can be found here.
Beta Was this translation helpful? Give feedback.
All reactions