Python 3.12: Should `TypeVar.__eq__` compare the typevar name and not the identity?

Hi there, I'm wondering if TypeVars should compare their name instead of their identity, for example here: ``` class Something[T]: abc: T class SomethingElse[T]: abc: T print(Something.__type_params__ == SomethingElse.__type_params__) # this is false ``` I have a library that uses generics quite a bit and I'm getting issues on Python 3.12 because the comparison doesn't work anymore (and also because we use TypeVars as key of a dictionary)

I don't think it makes sense to compare type params by name. The type params of the two classes in your example are not the same in any meaningful sense; they are completely independent and just happen to share a name. One of the aims of PEP 695 was to clarify the scope of type variables and ensure that type variables are clearly scoped to just a single class (or function or alias). El mar, 18 jul 2023 a las 12:22, Patrick Arminio (<patrick.arminio@gmail.com>) escribió:
Hi there, I'm wondering if TypeVars should compare their name instead of their identity, for example here:
``` class Something[T]: abc: T
class SomethingElse[T]: abc: T
print(Something.__type_params__ == SomethingElse.__type_params__) # this is false ```
I have a library that uses generics quite a bit and I'm getting issues on Python 3.12 because the comparison doesn't work anymore (and also because we use TypeVars as key of a dictionary) _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: jelle.zijlstra@gmail.com

I think I agree 😊 I need to check in my code where we make a copy of the TypeVar then 😊 On Tue, Jul 18, 2023 at 11:07 PM Jelle Zijlstra <jelle.zijlstra@gmail.com> wrote:
I don't think it makes sense to compare type params by name. The type params of the two classes in your example are not the same in any meaningful sense; they are completely independent and just happen to share a name. One of the aims of PEP 695 was to clarify the scope of type variables and ensure that type variables are clearly scoped to just a single class (or function or alias).
El mar, 18 jul 2023 a las 12:22, Patrick Arminio (< patrick.arminio@gmail.com>) escribió:
Hi there, I'm wondering if TypeVars should compare their name instead of their identity, for example here:
``` class Something[T]: abc: T
class SomethingElse[T]: abc: T
print(Something.__type_params__ == SomethingElse.__type_params__) # this is false ```
I have a library that uses generics quite a bit and I'm getting issues on Python 3.12 because the comparison doesn't work anymore (and also because we use TypeVars as key of a dictionary) _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: jelle.zijlstra@gmail.com
-- Patrick Arminio
participants (2)
-
Jelle Zijlstra
-
Patrick Arminio