New submission from Jason Curtis <[email protected]>:
Combining int and Enum, as with enum.IntEnum results in a class where __str__
cannot be effectively overridden. For example:
from enum import IntEnum
class myIntEnum(IntEnum):
x = 1
def __str__(self):
return 'aaaaAAAa'
f'{myIntEnum.x}, {str(myIntEnum.x)}'
Expected output:
'aaaaAAAa, aaaaAAAa'
Actual output:
'1, aaaaAAAa'
Overriding __str__ in this way works as expected if the inherited classes are
int or Enum individually. However, it does not work when inheriting (int, Enum)
or when inheriting (intEnum).
Presumably this is a side effect of Enum's mixin behavior documented at
https://docs.python.org/3/library/enum.html#others and it is possibly related
to https://bugs.python.org/issue18264 .
----------
components: Library (Lib)
messages: 347089
nosy: Jason Curtis
priority: normal
severity: normal
status: open
title: IntEnum f-string behavior can't be overridden
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37479>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com