hdl._ast: deprecate ValueCastable.lowermethod.
This commit is contained in:
parent
e2fd819742
commit
0da439cce1
7 changed files with 10 additions and 39 deletions
|
|
@ -1262,9 +1262,6 @@ class ValueCastable:
|
|||
if cls.shape is ValueCastable.shape:
|
||||
raise TypeError(f"Class '{cls.__name__}' deriving from 'ValueCastable' must override "
|
||||
"the 'shape' method")
|
||||
if not hasattr(cls.as_value, "_ValueCastable__memoized"):
|
||||
raise TypeError(f"Class '{cls.__name__}' deriving from 'ValueCastable' must decorate "
|
||||
"the 'as_value' method with the 'ValueCastable.lowermethod' decorator")
|
||||
|
||||
# The signatures and definitions of these methods are weird because they are present here for
|
||||
# documentation (and error checking above) purpose only and should not affect control flow.
|
||||
|
|
@ -1333,17 +1330,10 @@ class ValueCastable:
|
|||
"""
|
||||
return super().shape(*args, **kwargs) # :nocov:
|
||||
|
||||
# TODO(amaranth-0.6): remove
|
||||
@staticmethod
|
||||
@deprecated("`ValueCastable.lowermethod` is no longer required and will be removed in Amaranth 0.6")
|
||||
def lowermethod(func):
|
||||
"""Decorator to memoize lowering methods.
|
||||
|
||||
Ensures the decorated method is called only once, with subsequent method calls returning
|
||||
the object returned by the first first method call.
|
||||
|
||||
This decorator is required to decorate the :pc:`as_value` method of :pc:`ValueCastable`
|
||||
subclasses. This is to ensure that Amaranth's view of representation of all values stays
|
||||
internally consistent.
|
||||
"""
|
||||
@functools.wraps(func)
|
||||
def wrapper_memoized(self, *args, **kwargs):
|
||||
# Use `in self.__dict__` instead of `hasattr` to avoid interfering with custom
|
||||
|
|
|
|||
|
|
@ -178,7 +178,6 @@ class Record(ValueCastable):
|
|||
raise AttributeError("{} does not have a field '{}'. Did you mean one of: {}?"
|
||||
.format(reference, item, ", ".join(self.fields))) from None
|
||||
|
||||
@ValueCastable.lowermethod
|
||||
def as_value(self):
|
||||
return Cat(self.fields.values())
|
||||
|
||||
|
|
|
|||
|
|
@ -638,7 +638,6 @@ class View(ValueCastable):
|
|||
"""
|
||||
return self.__orig_layout
|
||||
|
||||
@ValueCastable.lowermethod
|
||||
def as_value(self):
|
||||
"""Get underlying value.
|
||||
|
||||
|
|
|
|||
|
|
@ -232,7 +232,6 @@ class EnumView(ValueCastable):
|
|||
"""Returns the underlying enum type."""
|
||||
return self.enum
|
||||
|
||||
@ValueCastable.lowermethod
|
||||
def as_value(self):
|
||||
"""Returns the underlying value."""
|
||||
return self.target
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue