Add __format__ to EnumMember
Make the format specifier 'd' able to be used when formatting them in f-strings as an alternative to an int()-cast. Change-Id: I4083aa0f4b0d8d10e3e11a29591cfbf5e5aca03d Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30902 Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch> Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
This commit is contained in:
parent
e673dfe92b
commit
d99f2dfbc3
@ -211,6 +211,11 @@ class EnumMember:
|
|||||||
def __index__(self):
|
def __index__(self):
|
||||||
return self.value.__index__()
|
return self.value.__index__()
|
||||||
|
|
||||||
|
def __format__(self, format_spec):
|
||||||
|
if format_spec.endswith('d'):
|
||||||
|
return format(self.value, format_spec)
|
||||||
|
return super().__format__(format_spec)
|
||||||
|
|
||||||
# note: we do not implement the __i*__ methods as they modify our value
|
# note: we do not implement the __i*__ methods as they modify our value
|
||||||
# inplace and we want to have a const
|
# inplace and we want to have a const
|
||||||
def __forbidden__(self, *args):
|
def __forbidden__(self, *args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user