mirror of
https://github.com/pyapp-kit/superqt.git
synced 2026-01-06 12:21:17 +01:00
Fix IntEnum for python 3.11 (#205)
This commit is contained in:
@@ -12,10 +12,8 @@ NONE_STRING = "----"
|
|||||||
|
|
||||||
def _get_name(enum_value: Enum):
|
def _get_name(enum_value: Enum):
|
||||||
"""Create human readable name if user does not implement `__str__`."""
|
"""Create human readable name if user does not implement `__str__`."""
|
||||||
if (
|
str_module = getattr(enum_value.__str__, "__module__", "enum")
|
||||||
enum_value.__str__.__module__ != "enum"
|
if str_module != "enum" and not str_module.startswith("shibokensupport"):
|
||||||
and not enum_value.__str__.__module__.startswith("shibokensupport")
|
|
||||||
):
|
|
||||||
# check if function was overloaded
|
# check if function was overloaded
|
||||||
name = str(enum_value)
|
name = str(enum_value)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from enum import Enum
|
from enum import Enum, IntEnum
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -36,6 +36,12 @@ class Enum4(Enum):
|
|||||||
c_3 = 3
|
c_3 = 3
|
||||||
|
|
||||||
|
|
||||||
|
class IntEnum1(IntEnum):
|
||||||
|
a = 1
|
||||||
|
b = 2
|
||||||
|
c = 5
|
||||||
|
|
||||||
|
|
||||||
def test_simple_create(qtbot):
|
def test_simple_create(qtbot):
|
||||||
enum = QEnumComboBox(enum_class=Enum1)
|
enum = QEnumComboBox(enum_class=Enum1)
|
||||||
qtbot.addWidget(enum)
|
qtbot.addWidget(enum)
|
||||||
@@ -129,3 +135,10 @@ def test_optional(qtbot):
|
|||||||
enum.setCurrentEnum(None)
|
enum.setCurrentEnum(None)
|
||||||
assert enum.currentText() == NONE_STRING
|
assert enum.currentText() == NONE_STRING
|
||||||
assert enum.currentEnum() is None
|
assert enum.currentEnum() is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_simple_create_int_enum(qtbot):
|
||||||
|
enum = QEnumComboBox(enum_class=IntEnum1)
|
||||||
|
qtbot.addWidget(enum)
|
||||||
|
assert enum.count() == 3
|
||||||
|
assert [enum.itemText(i) for i in range(enum.count())] == ["a", "b", "c"]
|
||||||
|
|||||||
Reference in New Issue
Block a user