Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IntEnum for python 3.11 #205

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/superqt/combobox/_enum_combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@

def _get_name(enum_value: Enum):
"""Create human readable name if user does not implement `__str__`."""
if (
enum_value.__str__.__module__ != "enum"
and not enum_value.__str__.__module__.startswith("shibokensupport")
):
str_module = getattr(enum_value.__str__, "__module__", "enum")
if str_module != "enum" and not str_module.startswith("shibokensupport"):
# check if function was overloaded
name = str(enum_value)
else:
Expand Down
15 changes: 14 additions & 1 deletion tests/test_enum_comb_box.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from enum import Enum
from enum import Enum, IntEnum

import pytest

Expand Down Expand Up @@ -36,6 +36,12 @@ class Enum4(Enum):
c_3 = 3


class IntEnum1(IntEnum):
a = 1
b = 2
c = 5


def test_simple_create(qtbot):
enum = QEnumComboBox(enum_class=Enum1)
qtbot.addWidget(enum)
Expand Down Expand Up @@ -129,3 +135,10 @@ def test_optional(qtbot):
enum.setCurrentEnum(None)
assert enum.currentText() == NONE_STRING
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"]