From a90bc7b91a5a4d92af6e487ef6a290bf2b4a6f2a Mon Sep 17 00:00:00 2001 From: Catherine Date: Wed, 27 Sep 2023 11:00:54 +0000 Subject: [PATCH] lib.wiring: create flipped interface from flipped signature. Fixes #914. Co-authored-by: Nelson Gauthier --- amaranth/lib/wiring.py | 3 +++ tests/test_lib_wiring.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/amaranth/lib/wiring.py b/amaranth/lib/wiring.py index 6534541..48351e5 100644 --- a/amaranth/lib/wiring.py +++ b/amaranth/lib/wiring.py @@ -535,6 +535,9 @@ class FlippedSignature: def __setattr__(self, name, value): return setattr(self.__unflipped, name, value) + def create(self, *, path=()): + return flipped(self.__unflipped.create(path=path)) + def __repr__(self): return f"{self.__unflipped!r}.flip()" diff --git a/tests/test_lib_wiring.py b/tests/test_lib_wiring.py index ccdc3d1..aa23ced 100644 --- a/tests/test_lib_wiring.py +++ b/tests/test_lib_wiring.py @@ -583,6 +583,18 @@ class FlippedInterfaceTestCase(unittest.TestCase): with self.assertRaisesRegex(TypeError, r"^flipped\(\) can only flip an interface object, not Signature\({}\)$"): flipped(Signature({})) + + def test_create_subclass_flipped(self): + class CustomInterface(Interface): + def custom_method(self): + return 69 + + class CustomSignature(Signature): + def create(self, *, path=()): + return CustomInterface(self, path=path) + + flipped_interface = CustomSignature({}).flip().create() + self.assertTrue(hasattr(flipped_interface, "custom_method")) class ConnectTestCase(unittest.TestCase):