@@ -738,6 +738,45 @@ def test_subscript_meta(self):
738738 self .assertEqual (Union [T , int ][GenericMeta ], Union [GenericMeta , int ])
739739 self .assertEqual (Callable [..., GenericMeta ].__args__ , (Ellipsis , GenericMeta ))
740740
741+ def test_generic_hashes (self ):
742+ import mod
743+ class A (Generic [T ]):
744+ ...
745+
746+ class B (Generic [T ]):
747+ class A (Generic [T ]):
748+ ...
749+
750+ self .assertEqual (A , A )
751+ self .assertEqual (mod .A [str ], mod .A [str ])
752+ self .assertEqual (B .A , B .A )
753+ self .assertEqual (mod .B .A [B .A [str ]], mod .B .A [B .A [str ]])
754+
755+ self .assertNotEqual (A , B .A )
756+ self .assertNotEqual (A , mod .A )
757+ self .assertNotEqual (A , mod .B .A )
758+ self .assertNotEqual (B .A , mod .A )
759+ self .assertNotEqual (B .A , mod .B .A )
760+
761+ self .assertNotEqual (A [str ], B .A [str ])
762+ self .assertNotEqual (A [List [Any ]], B .A [List [Any ]])
763+ self .assertNotEqual (A [str ], mod .A [str ])
764+ self .assertNotEqual (A [str ], mod .B .A [str ])
765+ self .assertNotEqual (B .A [int ], mod .A [int ])
766+ self .assertNotEqual (B .A [List [Any ]], mod .B .A [List [Any ]])
767+
768+ self .assertNotEqual (Tuple [A [str ]], Tuple [B .A [str ]])
769+ self .assertNotEqual (Tuple [A [List [Any ]]], Tuple [B .A [List [Any ]]])
770+ self .assertNotEqual (Union [str , A [str ]], Union [str , mod .A [str ]])
771+ self .assertNotEqual (Union [A [str ], A [str ]], Union [A [str ], mod .A [str ]])
772+ self .assertNotEqual (typing .FrozenSet [A [str ]], typing .FrozenSet [mod .B .A [str ]])
773+
774+ if sys .version_info [:2 ] > (3 , 2 ):
775+ self .assertTrue (repr (Tuple [A [str ]]).endswith ('<locals>.A[str]]' ))
776+ self .assertTrue (repr (Tuple [B .A [str ]]).endswith ('<locals>.B.A[str]]' ))
777+ self .assertTrue (repr (Tuple [mod .A [str ]]).endswith ('mod.A[str]]' ))
778+ self .assertTrue (repr (Tuple [mod .B .A [str ]]).endswith ('mod.B.A[str]]' ))
779+
741780 def test_extended_generic_rules_eq (self ):
742781 T = TypeVar ('T' )
743782 U = TypeVar ('U' )
0 commit comments