@@ -84,7 +84,12 @@ def __or__(self, other: "TypeAttribute"):
8484 return self .join (other )
8585
8686 def __eq__ (self , value : object ) -> bool :
87- return isinstance (value , TypeAttribute ) and self .is_equal (value )
87+ return isinstance (value , TypeAttribute ) and self .is_structurally_equal (value )
88+
89+ @abstractmethod
90+ def is_structurally_equal (
91+ self , other : "Attribute" , context : dict | None = None
92+ ) -> bool : ...
8893
8994 @abstractmethod
9095 def __hash__ (self ) -> int : ...
@@ -286,13 +291,6 @@ def __eq__(self, other: object) -> bool:
286291 return False
287292 return self .data == other .data and self .type == other .type
288293
289- def is_equal (self , other : TypeAttribute ) -> bool :
290- return (
291- isinstance (other , Literal )
292- and self .type .is_equal (other .type )
293- and self .data == other .data
294- )
295-
296294 def is_subseteq_TypeVar (self , other : "TypeVar" ) -> bool :
297295 return self .is_subseteq (other .bound )
298296
@@ -317,7 +315,7 @@ def is_structurally_equal(
317315 return (
318316 isinstance (other , Literal )
319317 and self .data == other .data
320- and self .type .is_equal (other .type )
318+ and self .type .is_structurally_equal (other .type , context = context )
321319 )
322320
323321 def serialize (self , serializer : "Serializer" ) -> "SerializationUnit" :
@@ -355,9 +353,6 @@ def __init__(
355353 types = types .union ({typ })
356354 self .types = types
357355
358- def is_equal (self , other : TypeAttribute ) -> bool :
359- return isinstance (other , Union ) and self .types == other .types
360-
361356 def is_subseteq_fallback (self , other : TypeAttribute ) -> bool :
362357 return all (t .is_subseteq (other ) for t in self .types )
363358
@@ -416,13 +411,6 @@ def __init__(self, name: str, bound: TypeAttribute | None = None):
416411 self .varname = name
417412 self .bound = bound or AnyType ()
418413
419- def is_equal (self , other : TypeAttribute ) -> bool :
420- return (
421- isinstance (other , TypeVar )
422- and self .varname == other .varname
423- and self .bound .is_equal (other .bound )
424- )
425-
426414 def is_subseteq_TypeVar (self , other : "TypeVar" ) -> bool :
427415 return self .bound .is_subseteq (other .bound )
428416
@@ -447,7 +435,7 @@ def is_structurally_equal(
447435 return (
448436 isinstance (other , TypeVar )
449437 and self .varname == other .varname
450- and self .bound .is_equal (other .bound )
438+ and self .bound .is_structurally_equal (other .bound , context = context )
451439 )
452440
453441 def serialize (self , serializer : "Serializer" ) -> "SerializationUnit" :
@@ -482,7 +470,7 @@ def print_impl(self, printer: Printer) -> None:
482470 def is_structurally_equal (
483471 self , other : Attribute , context : dict | None = None
484472 ) -> bool :
485- return isinstance (other , Vararg ) and self .typ .is_equal (other .typ )
473+ return isinstance (other , Vararg ) and self .typ .is_structurally_equal (other .typ )
486474
487475 def serialize (self , serializer : "Serializer" ) -> "SerializationUnit" :
488476 return serializer .serialize_vararg (self )
@@ -626,12 +614,17 @@ def is_structurally_equal(
626614 return False
627615 if len (self .vars ) != len (other .vars ):
628616 return False
629- if any (not v .is_equal (o ) for v , o in zip (self .vars , other .vars )):
617+ if any (
618+ not v .is_structurally_equal (o , context = context )
619+ for v , o in zip (self .vars , other .vars )
620+ ):
630621 return False
631622 if self .vararg is None and other .vararg is None :
632623 return True
633624 if self .vararg is not None and other .vararg is not None :
634- return self .vararg .typ .is_equal (other .vararg .typ )
625+ return self .vararg .typ .is_structurally_equal (
626+ other .vararg .typ , context = context
627+ )
635628 return False
636629
637630 def serialize (self , serializer : "Serializer" ) -> "SerializationUnit" :
0 commit comments