From bef2052c1e883e9c539368ad1bfad354df4c4608 Mon Sep 17 00:00:00 2001 From: Catherine Date: Mon, 27 Feb 2023 22:31:17 +0000 Subject: [PATCH] hdl.ast: implement `Value.__pos__`. --- amaranth/hdl/ast.py | 3 +++ tests/test_hdl_ast.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/amaranth/hdl/ast.py b/amaranth/hdl/ast.py index 6a6cbee..a97b90f 100644 --- a/amaranth/hdl/ast.py +++ b/amaranth/hdl/ast.py @@ -166,6 +166,9 @@ class Value(metaclass=ABCMeta): def __bool__(self): raise TypeError("Attempted to convert Amaranth value to Python boolean") + def __pos__(self): + return self + def __invert__(self): return Operator("~", [self]) def __neg__(self): diff --git a/tests/test_hdl_ast.py b/tests/test_hdl_ast.py index 38502e1..6bc7f49 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -397,6 +397,9 @@ class OperatorTestCase(FHDLTestCase): self.assertEqual(repr(v), "(s (const 4'd1))") self.assertEqual(v.shape(), signed(4)) + def test_pos(self): + self.assertRepr(+Const(10), "(const 4'd10)") + def test_neg(self): v1 = -Const(0, unsigned(4)) self.assertEqual(repr(v1), "(- (const 4'd0))")