Beispiel #1
0
 def testReverseOperatorsWithInheritance(self):
     src1 = textwrap.dedent("""
   class A(object):
     def __add__(self, other: B) -> int
     def __add__(self, other: C) -> bool
     def __rdiv__(self, other: A) -> complex
   class B(object):
     def __radd__(self, other: A) -> str
     def __rmul__(self, other: A) -> float
   class C(A):
     def __add__(self, other: A) -> bool
     def __radd__(self, other: A) -> float
     def __rmul__(self, other: A) -> float
 """)
     src2 = textwrap.dedent("""
   class A(object):
     def __add__(self, other: B) -> int  # unchanged
     def __add__(self, other: C) -> float  # overwritten
     def __div__(self, other: A) -> complex  # added, __rdiv__ removed
     def __mul__(self, other: B) -> float  # added, __rmul__ from B
     def __mul__(self, other: C) -> float  # added, __rmul__ from C
   class B(object):
     pass
   class C(A):
     def __add__(self, other: A) -> bool
 """)
     tree = self.ParseWithLookup(src1)
     tree = tree.Visit(transforms.PreprocessReverseOperatorsVisitor())
     self.AssertSourceEquals(tree, src2)
Beispiel #2
0
 def testPreprocessReverseOperatorsVisitor(self):
     src1 = textwrap.dedent("""
   class A():
     def __add__(self, other: B) -> int
     def __rdiv__(self, other: A) -> float
     def __rmod__(self, other: B) -> str
   class B():
     def __radd__(self, other: A) -> complex  # ignored
     def __rmul__(self, other: A) -> complex
 """)
     src2 = textwrap.dedent("""
   class A():
     def __add__(self, other: B) -> int
     def __div__(self, other: A) -> float
     def __mul__(self, other: B) -> complex
   class B():
     def __mod__(self, other: A) -> str
 """)
     tree = self.ParseWithLookup(src1)
     tree = tree.Visit(transforms.PreprocessReverseOperatorsVisitor())
     self.AssertSourceEquals(tree, src2)