You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It works but if I have several function taking a generic constraint with the same 2 type. I have to write every time the same T: (int , str)
It is not good. For instance If to change the constraint, I have to change it everywhere.
Therefore what I propose is a way to say that type that T can take comes from a Union type. If the constraint change. It has thefollowing advantage. If I have to change the constraint I only have to change the union type.
This isn't something mypy can introduce as a type checker - you're proposing either a python syntax change or at least a new typing core feature. Consider asking on Python's Discourse (https://discuss.python.org/c/typing/32) instead.
I know to constraint a generic being a type in a list. See the example
If I want to do the same with the python 3.13 generic syntax, I write this code:
It works but if I have several function taking a generic constraint with the same 2 type. I have to write every time the same T: (int , str)
It is not good. For instance If to change the constraint, I have to change it everywhere.
Therefore what I propose is a way to say that type that T can take comes from a Union type. If the constraint change. It has thefollowing advantage. If I have to change the constraint I only have to change the union type.
concrete example of what I would like to have
I don t think this feature exist. I already ask. There (https://stackoverflow.com/questions/79126319/how-to-constrain-a-generic-type-with-an-alias-derived-from-a-union-type-in-pytho) for instance
The text was updated successfully, but these errors were encountered: