lib.wiring: fix equality of FlippedSignature with other object.

Fixes #882.
This commit is contained in:
Catherine 2023-08-31 18:59:12 +00:00
parent cfd4f9c84e
commit 44d5fac01c
2 changed files with 17 additions and 3 deletions

View file

@ -484,9 +484,11 @@ class FlippedSignature:
return self.flip() == other.flip()
else:
# Delegate comparisons back to Signature (or its descendant) by flipping the arguments;
# equality must be reflexive but the implementation of __eq__ need not be, and we can
# take advantage of it here.
return other == self
# equality must be reflexive but the implementation of `__eq__` need not be, and we can
# take advantage of it here. This is done by returning `NotImplemented`, otherwise if
# the other object cannot be compared to a `FlippedSignature` either this will result
# in infinite recursion.
return NotImplemented
# These methods do not access instance variables and so their implementation can be shared
# between the normal and the flipped member collections.

View file

@ -832,3 +832,15 @@ class ComponentTestCase(unittest.TestCase):
r"a signature member; did you mean 'val2: In\(MockValueCastable\)' or "
r"'val2: Out\(MockValueCastable\)'\?$"):
C3().signature
def test_bug_882(self):
class PageBuffer(Component):
rand: Signature({}).flip()
other: Out(1)
with self.assertWarnsRegex(SyntaxWarning,
r"^Component '.+\.PageBuffer' has an annotation 'rand: Signature\({}\)\.flip\(\)', "
r"which is not a signature member; did you mean "
r"'rand: In\(Signature\({}\)\.flip\(\)\)' or "
r"'rand: Out\(Signature\({}\)\.flip\(\)\)'\?$"):
PageBuffer()