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

Conversation

Czaki
Copy link
Contributor

@Czaki Czaki commented Sep 23, 2023

Closes #202

The error described in #202 is Python 3.11 specific. Caused by this change:

Changed in version 3.11: str() is now int.str() to better support the replacement of existing constants use-case. format() was already int.format() for that same reason.

Described in documentation.

I have changed the _get_name strategy to assume that if we cannot determine the __str__ module, then we could assume that it is not overwritten by the user and use the default strategy.

Summary by CodeRabbit

  • Bug Fix: Enhanced the _get_name function in src/superqt/combobox/_enum_combobox.py to handle cases where the __str__ method of the enum_value object is overridden or belongs to a different module. This ensures more robust and reliable functionality.
  • Test: Added a new test case test_simple_create_int_enum in tests/test_enum_comb_box.py to verify the correct creation of a QEnumComboBox with an IntEnum1 class, improving the overall test coverage.

@coderabbitai
Copy link

coderabbitai bot commented Sep 23, 2023

Walkthrough

The changes enhance the robustness of the _get_name function in handling overridden __str__ methods and add a new test case for creating a QEnumComboBox with an IntEnum class.

Changes

File Summary
src/superqt/combobox/_enum_combobox.py Improved the _get_name function to handle cases where the __str__ method of the enum_value object is overridden or belongs to a different module. The change uses getattr to retrieve the __module__ attribute of the __str__ method, providing a more robust check.
tests/test_enum_comb_box.py Added a new IntEnum1 class and a test function test_simple_create_int_enum. The test verifies the creation of a QEnumComboBox with IntEnum1 as the enum class and checks that the combo box has three items with the texts "a", "b", and "c".

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between 409d19e and 549bd9b.
Files selected for processing (2)
  • src/superqt/combobox/_enum_combobox.py (1 hunks)
  • tests/test_enum_comb_box.py (3 hunks)
Files skipped from review due to trivial changes (1)
  • src/superqt/combobox/_enum_combobox.py
Additional comments (Suppressed): 3
tests/test_enum_comb_box.py (3)
  • 1-4: The import of IntEnum is new and necessary for the newly introduced IntEnum1 class. This change seems appropriate.

  • 39-42: A new IntEnum1 class is introduced, extending from IntEnum. This class is used in the new test function test_simple_create_int_enum.

  • 140-144: A new test function test_simple_create_int_enum is added. It creates a QEnumComboBox with IntEnum1 as the enum class and verifies that the combo box correctly displays the enum values. The test seems to be well written and covers the necessary assertions.

@codecov
Copy link

codecov bot commented Sep 23, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (409d19e) 87.30% compared to head (549bd9b) 87.30%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #205   +/-   ##
=======================================
  Coverage   87.30%   87.30%           
=======================================
  Files          45       45           
  Lines        3324     3325    +1     
=======================================
+ Hits         2902     2903    +1     
  Misses        422      422           
Files Changed Coverage Δ
src/superqt/combobox/_enum_combobox.py 94.11% <100.00%> (+0.08%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tlambert03
Copy link
Member

Thank you! And thanks also for the explanation

@tlambert03 tlambert03 merged commit 830fe38 into pyapp-kit:main Sep 23, 2023
42 checks passed
@Czaki Czaki deleted the bugfix/enumint branch September 24, 2023 06:29
@tlambert03 tlambert03 added the bug Something isn't working label Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

QEnumComboBox _get_name fails on IntEnum
2 participants