-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Enum with str
or int
Mixin Breaking Change in Python 3.11
#100458
Comments
@anze3db docs: https://docs.python.org/3.11/library/enum.html#enum.StrEnum |
@JosephSBoyle yes, we replaced the str mixin with |
Coincidentally I've also used the mixin approach you describe in professional projects, which suggests that this use is at the very least not uncommon. As such it makes sense that the docs also suggest a way to achieve the old behaviour, like you say @anze3db. I've added a small suggestion to your PR; hopefully that will help resolve things for others in the same position! |
Thank you! The text that you added would have helped me a lot when I was figuring out how to fix this 👍 |
…whatsnew/3.11.rst (GH-100387) Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com> Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
…n the whatsnew/3.11.rst (pythonGH-100387) (cherry picked from commit e665563) Co-authored-by: Anže Pečar <anze@pecar.me> Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com> Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
* main: (463 commits) pythongh-104057: Fix direct invocation of test_super (python#104064) pythongh-87092: Expose assembler to unit tests (python#103988) pythongh-97696: asyncio eager tasks factory (python#102853) pythongh-84436: Immortalize in _PyStructSequence_InitBuiltinWithFlags() (pythongh-104054) pythongh-104057: Fix direct invocation of test_module (pythonGH-104059) pythongh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst (pythonGH-100387) pythongh-104018: disallow "z" format specifier in %-format of byte strings (pythonGH-104033) pythongh-104016: Fixed off by 1 error in f string tokenizer (python#104047) pythonGH-103629: Update Unpack's repr in compliance with PEP 692 (python#104048) pythongh-102799: replace sys.exc_info by sys.exception in inspect and traceback modules (python#104032) Fix typo in "expected" word in few source files (python#104034) pythongh-103824: fix use-after-free error in Parser/tokenizer.c (python#103993) pythongh-104035: Do not ignore user-defined `__{get,set}state__` in slotted frozen dataclasses (python#104041) pythongh-104028: Reduce object creation while calling callback function from gc (pythongh-104030) pythongh-104036: Fix direct invocation of test_typing (python#104037) pythongh-102213: Optimize the performance of `__getattr__` (pythonGH-103761) pythongh-103895: Improve how invalid `Exception.__notes__` are displayed (python#103897) Adjust expression from `==` to `!=` in alignment with the meaning of the paragraph. (pythonGH-104021) pythongh-88496: Fix IDLE test hang on macOS (python#104025) Improve int test coverage (python#104024) ...
…m.KEY, which works on Python<3.11 but broke in 3.11 (see: python/cpython#100458)
* Pin transient urllib3 dependency to unbreak requests==2.30 * Pin to requests-toolbelt>=1 instead of pinning transient urllib3 * Add back importlib-metadata dependency * Allow Python 3.11 and add version to CI matrix * Pin urllib3 per requests issue recommendation, leave TODO * Pin transient urllib3 dependency to unbreak requests==2.30 * Pin to requests-toolbelt>=1 instead of pinning transient urllib3 * Add back importlib-metadata dependency * Tediously update all enum usages to use Enum.KEY.value instead of Enum.KEY, which works on Python<3.11 but broke in 3.11 (see: python/cpython#100458) * Move FR-specific upload_image_chips to kolena.fr._utils; remove kolena.fr._consts; rename some already-hidden classes to remove leading underscore (already in underscored files) * Revert {_=>}BatchedLoader diff, this PR is not the place for that * Start updating integration tests with new description edit semantics * Add missing pytest-depends dev dependency * Fix FR test__edit__reset * Assert description update without version update * Unbreak upload_image_chips after move * Unbreak FR test suite test__load by comparing data to data * Remove bad comparison
Also, from enum import Enum
from http import HTTPStatus
HTTPStatus.__str__ = Enum.__str__ |
BREAKING CHANGE: class Type(str, Enum) --> class Type(StrEnum) python/cpython#100458
BREAKING CHANGE: class Type(str, Enum) --> class Type(StrEnum) python/cpython#100458
Improving the What's New documentation was a good call, thank you! While I also found this needlessly breaking when updating my work codebase, I don't think there's anything left to be done here. |
Fix python/cpython#100458 Fix a pandas incompatibility commit-id:f0b690de
Fix python/cpython#100458 Fix a pandas incompatibility commit-id:f0b690de
in 3.11 these f strings change for the enum python/cpython#100458 so just do `.value` ## How I Tested These Changes bk passes
another place effected by python/cpython#100458 the string `<GraphQLWS.PROTOCOL: 'graphql-ws'>` was being sent instead of `graphql-ws` ## How I Tested These Changes added assert to test that would have caught this
another place effected by python/cpython#100458 the string `<GraphQLWS.PROTOCOL: 'graphql-ws'>` was being sent instead of `graphql-ws` ## How I Tested These Changes added assert to test that would have caught this
Changes made: * Replace usage of Enum plus str mixin with StrEnum, as per python/cpython#100458
Changes made: * Replace usage of Enum plus str mixin with StrEnum, as per python/cpython#100458 * Sync "typing_extensions" version between requirements.txt and pyproject.toml
Changes made: * Replace usage of Enum plus str mixin with StrEnum, as per python/cpython#100458 * Sync "typing_extensions" version between requirements.txt and pyproject.toml
support python3.11 python/cpython#100458 python/cpython#84247
## Describe your changes python/cpython#100458 Quarot require python>=3.11 where the mixin usage of (str, Enum) did not work. This PR is used to create olive strEnum based on python version. ## Checklist before requesting a review - [ ] Add unit tests for this change. - [ ] Make sure all tests can pass. - [ ] Update documents if necessary. - [ ] Lint and apply fixes to your code by running `lintrunner -a` - [ ] Is this a user-facing change? If yes, give a description of this change to be included in the release notes. - [ ] Is this PR including examples changes? If yes, please remember to update [example documentation](https://github.com/microsoft/Olive/blob/main/docs/source/examples.md) in a follow-up PR. ## (Optional) Issue link
## Describe your changes python/cpython#100458 Quarot require python>=3.11 where the mixin usage of (str, Enum) did not work. This PR is used to create olive strEnum based on python version. ## Checklist before requesting a review - [ ] Add unit tests for this change. - [ ] Make sure all tests can pass. - [ ] Update documents if necessary. - [ ] Lint and apply fixes to your code by running `lintrunner -a` - [ ] Is this a user-facing change? If yes, give a description of this change to be included in the release notes. - [ ] Is this PR including examples changes? If yes, please remember to update [example documentation](https://github.com/microsoft/Olive/blob/main/docs/source/examples.md) in a follow-up PR. ## (Optional) Issue link
Bug report
Looks like there was a breaking change with the way str and int mixins work with Enums in Python 3.11:
The same goes for Enum classes with the
int
mixin.In my project we were relying on Foo.BAR to return the enum value, so this change broke our code. We fixed it by replacing str Enum mixin with the newly added StrEnum class (thanks for that, it's exactly what we needed!).
I think reverting the breaking change would only introduce another breaking change so that's probably not the way to go. But maybe updating the whatsnew page and call out the change there could help people stumbling into this when doing the upgrade. I've found the existing point about this change in the release notes a little bit confusing and I have already opened a PR to try and clear it up a bit: #100387
I've also written a longer blog post about it here, and there has been some lively discussion in r/python.
Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: