Skip to content

Commit 88f0401

Browse files
committed
Deprecations for RFC 73.
1 parent df32b3d commit 88f0401

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

amaranth/lib/data.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,10 @@ def eq(self, other):
777777
"""
778778
if isinstance(other, ValueCastable):
779779
if not self.shape() == Layout.cast(other.shape()):
780-
raise TypeError(f"Cannot assign value with shape {other.shape()} to view with layout {self.shape()}")
780+
#raise TypeError(f"Cannot assign value with shape {other.shape()} to view with layout {self.shape()}")
781+
# TODO(amaranth-0.7): remove
782+
warnings.warn(f"Assigning value with shape {other.shape()} to view with layout {self.shape()} will "
783+
"become an error in Amaranth 0.7", DeprecationWarning, stacklevel=2)
781784
return self.as_value().eq(other)
782785

783786
def __getitem__(self, key):

amaranth/lib/enum.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ def eq(self, other):
250250
"""
251251
if isinstance(other, ValueCastable):
252252
if not self.shape() == other.shape():
253-
raise TypeError(f"Cannot assign value with shape {other.shape()} to value with shape {self.shape()}")
253+
#raise TypeError(f"Cannot assign value with shape {other.shape()} to value with shape {self.shape()}")
254+
# TODO(amaranth-0.7): remove
255+
warnings.warn(f"Assigning value with shape {other.shape()} to value with shape {self.shape()} will "
256+
"become an error in Amaranth 0.7", DeprecationWarning, stacklevel=2)
254257
return self.as_value().eq(other)
255258

256259
def __add__(self, other):

amaranth/lib/wiring.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,9 +1596,13 @@ def connect_value(*, out_path, in_path, src_loc_at):
15961596
try:
15971597
eq = in_value.eq
15981598
except AttributeError:
1599-
raise ConnectionError(
1600-
f"Cannot connect input member {_format_path(in_path)} because the input "
1601-
f"value {in_value!r} does not support assignment")
1599+
#raise ConnectionError(
1600+
# f"Cannot connect input member {_format_path(in_path)} because the input "
1601+
# f"value {in_value!r} does not support assignment")
1602+
# TODO(amaranth-0.7): remove
1603+
warnings.warn(f"ValueCastable input value {in_value!r} does not support assignment; "
1604+
"this will become an error in Amaranth 0.7", DeprecationWarning, stacklevel=2)
1605+
eq = Value.cast(in_value).eq
16021606
# The `eq()` method may take a `src_loc_at` argument; provide it if it does.
16031607
if 'src_loc_at' in inspect.signature(eq).parameters:
16041608
kwargs = {'src_loc_at': src_loc_at + 1}
@@ -1607,9 +1611,13 @@ def connect_value(*, out_path, in_path, src_loc_at):
16071611
try:
16081612
connections.append(eq(out_value, **kwargs))
16091613
except Exception as e:
1610-
raise ConnectionError(
1611-
f"Cannot connect input member {_format_path(in_path)} to output member "
1612-
f"{_format_path(out_path)} because assignment failed") from e
1614+
#raise ConnectionError(
1615+
# f"Cannot connect input member {_format_path(in_path)} to output member "
1616+
# f"{_format_path(out_path)} because assignment failed") from e
1617+
# TODO(amaranth-0.7): remove
1618+
warnings.warn(f"Assigning to ValueCastable input value {in_value!r} failed; "
1619+
"this will become an error in Amaranth 0.7", DeprecationWarning, stacklevel=2)
1620+
connections.append(Value.cast(in_value).eq(out_value, src_loc_at=src_loc_at + 1))
16131621
def connect_dimensions(dimensions, *, out_path, in_path, src_loc_at):
16141622
if not dimensions:
16151623
return connect_value(out_path=out_path, in_path=in_path, src_loc_at=src_loc_at)

tests/test_lib_data.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,8 +1354,11 @@ class S2(data.Struct):
13541354

13551355
s = Signal(S)
13561356
s2 = Signal(S2)
1357-
with self.assertRaisesRegex(TypeError,
1358-
r"^Cannot assign value with shape <class '.+?\.S2'> to view with layout <class '.+?\.S'>$"):
1357+
#with self.assertRaisesRegex(TypeError,
1358+
# r"^Cannot assign value with shape <class '.+?\.S2'> to view with layout <class '.+?\.S'>$"):
1359+
# TODO(amaranth-0.7): remove
1360+
with self.assertWarnsRegex(DeprecationWarning,
1361+
r"^Assigning value with shape .* to view with layout .* will become an error in Amaranth 0.7$"):
13591362
s.eq(s2)
13601363

13611364

tests/test_lib_enum.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ class EnumB(Enum, shape=unsigned(2)):
350350

351351
s = Signal(EnumA)
352352
s2 = Signal(EnumB)
353-
with self.assertRaisesRegex(TypeError,
354-
r"^Cannot assign value with shape <enum 'EnumB'> to value with shape <enum 'EnumA'>$"):
353+
#with self.assertRaisesRegex(TypeError,
354+
# r"^Cannot assign value with shape <enum 'EnumB'> to value with shape <enum 'EnumA'>$"):
355+
# TODO(amaranth-0.7): remove
356+
with self.assertWarnsRegex(DeprecationWarning,
357+
r"^Assigning value with shape .* to value with shape .* will become an error in Amaranth 0.7$"):
355358
s.eq(s2)

tests/test_lib_wiring.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,12 @@ class FirstDelimited(data.Struct):
860860
first: 1
861861

862862
m = Module()
863-
with self.assertRaisesRegex(ConnectionError,
864-
r"^Cannot connect input member 'q\.a' to output member 'p\.a' because assignment "
865-
r"failed$"):
863+
#with self.assertRaisesRegex(ConnectionError,
864+
# r"^Cannot connect input member 'q\.a' to output member 'p\.a' because assignment "
865+
# r"failed$"):
866+
# TODO(amaranth-0.7): remove
867+
with self.assertWarnsRegex(DeprecationWarning,
868+
r"^Assigning value with shape .* to view with layout .* will become an error in Amaranth 0.7$"):
866869
connect(m,
867870
p=NS(signature=Signature({"a": Out(LastDelimited)}),
868871
a=Signal(LastDelimited)),

0 commit comments

Comments
 (0)