lib.enum: add .format() implementation.
This commit is contained in:
parent
3c870d6b73
commit
1fdd9bf4e9
2 changed files with 41 additions and 3 deletions
|
|
@ -2,8 +2,8 @@ import enum as py_enum
|
|||
import warnings
|
||||
import operator
|
||||
|
||||
from ..hdl import Value, ValueCastable, Shape, ShapeCastable, Const, SyntaxWarning
|
||||
from ..hdl._repr import *
|
||||
from ..hdl import Value, ValueCastable, Shape, ShapeCastable, Const, SyntaxWarning, Format
|
||||
from ..hdl._repr import Repr, FormatEnum
|
||||
|
||||
|
||||
__all__ = py_enum.__all__ + ["EnumView", "FlagView"]
|
||||
|
|
@ -176,6 +176,11 @@ class EnumType(ShapeCastable, py_enum.EnumMeta):
|
|||
def from_bits(cls, bits):
|
||||
return cls(bits)
|
||||
|
||||
def format(cls, value, format_spec):
|
||||
if format_spec != "":
|
||||
raise ValueError(f"Format specifier {format_spec!r} is not supported for enums")
|
||||
return Format.Enum(value, cls)
|
||||
|
||||
def _value_repr(cls, value):
|
||||
yield Repr(FormatEnum(cls), value)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue