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

Corrected Colors enum under Python 3.11 #2590

Merged
merged 3 commits into from
Nov 29, 2022

Conversation

LiraNuna
Copy link
Contributor

@LiraNuna LiraNuna commented Oct 26, 2022

Python 3.11 have made some changes to how mixed-in Enum formatting works. From the changelog:

Changed Enum.__format__() (the default for format(), str.format() and f-strings) of enums with mixed-in types (e.g. int, str) to also include the class name in the output, not just the member’s key. This matches the existing behavior of enum.Enum.__str__(), returning e.g. 'AnEnum.MEMBER' for an enum AnEnum(str, Enum) instead of just 'MEMBER'.

This PR fixes this issue by using the new StrEnum from Python 3.11 if available, substituting it for a subclass otherwise.

NOTE: I would recommend adding python 3.11 to unit tests before merging this one.

Fixes #2589

@LiraNuna LiraNuna requested a review from a team as a code owner October 26, 2022 18:27
@codecov
Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Base: 87.866% // Head: 87.870% // Increases project coverage by +0.004% 🎉

Coverage data is based on head (12972b7) compared to base (aef2673).
Patch coverage: 100.000% of modified lines in pull request are covered.

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2590       +/-   ##
=============================================
+ Coverage   87.866%   87.870%   +0.004%     
=============================================
  Files           71        71               
  Lines         5357      5359        +2     
  Branches       893       893               
=============================================
+ Hits          4707      4709        +2     
  Misses         471       471               
  Partials       179       179               
Impacted Files Coverage Δ
sanic/log.py 100.000% <100.000%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@LiraNuna LiraNuna force-pushed the python311_strenum branch 2 times, most recently from 3f8c44a to da3fccb Compare October 26, 2022 18:40
@ahopkins
Copy link
Member

ahopkins commented Oct 26, 2022

NOTE: I would recommend adding python 3.11 to unit tests before merging this one.

Yup, that is a tomorrow task 😎 I think uvloop added 3.11, need to double check if that was released otherwise we need to wait.

sanic/log.py Show resolved Hide resolved
@ahopkins ahopkins merged commit 0909e94 into sanic-org:main Nov 29, 2022
awesomo4000 pushed a commit to awesomo4000/sanic that referenced this pull request Dec 3, 2022
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
Fixes sanic-org#2589
@LiraNuna LiraNuna deleted the python311_strenum branch July 30, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sanic colors with python 3.11 displayed incorrectly
2 participants