-
Notifications
You must be signed in to change notification settings - Fork 36
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
Test failures in Python 3.11.0b3 #326
Comments
This is because enum members do no longer have attributes with all other enum members. Python 3.10: >>> from enum import Enum
>>> class Color(Enum):
... RED = 1
... GREEN = 2
... BLUE = 3
...
>>> Color.RED
<Color.RED: 1>
>>> Color.RED.RED
<Color.RED: 1>
>>> Color.RED.RED.RED
<Color.RED: 1>
>>> Color.RED.RED.RED.BLUE
<Color.BLUE: 3>
>>> Color.RED.RED.RED.BLUE.BLUE.GREEN.RED
<Color.RED: 1> Python 3.11:
That assert there IMHO makes no sense because |
Thanks for reporting this issue @major. I'd like to propose that we wait until the next release of python 3.11 or until python/cpython#93910 is resolved before patching this library. |
@parthea Thanks for having a look. At the moment, it's holding up about ~ 20 Google Cloud SDK packages in Fedora rawhide (next release). We have a feature freeze for that one in August, so hopefully we can get this moving before then. 🤞🏻 Relevant Fedora bug: BZ 2099815 |
I suppose that if we know how to patch, we can apply the patch temporarily in Fedora. |
This way, the tests pass with both Python 3.11.0b3 and Python 3.10.5. diff --git a/proto/enums.py b/proto/enums.py
index 6f13d32..6207ad7 100644
--- a/proto/enums.py
+++ b/proto/enums.py
@@ -58,8 +58,11 @@ class ProtoEnumMeta(enum.EnumMeta):
# In 3.7 onwards, we can define an _ignore_ attribute and do some
# mucking around with that.
if pb_options in attrs._member_names:
- idx = attrs._member_names.index(pb_options)
- attrs._member_names.pop(idx)
+ if isinstance(attrs._member_names, list):
+ idx = attrs._member_names.index(pb_options)
+ attrs._member_names.pop(idx)
+ else: # Python 3.11.0b3
+ del attrs._member_names[pb_options]
# Make the descriptor.
enum_desc = descriptor_pb2.EnumDescriptorProto(
diff --git a/tests/test_enum_total_ordering.py b/tests/test_enum_total_ordering.py
index ad7a369..584a183 100644
--- a/tests/test_enum_total_ordering.py
+++ b/tests/test_enum_total_ordering.py
@@ -49,7 +49,11 @@ def test_total_ordering_w_other_enum_type():
for item in enums_test.OtherEnum:
assert not to_compare == item
- assert to_compare.SOME_VALUE != item
+ assert type(to_compare).SOME_VALUE != item
+ try:
+ assert to_compare.SOME_VALUE != item
+ except AttributeError: # Python 3.11.0b3
+ pass
with pytest.raises(TypeError):
assert not to_compare < item
with pytest.raises(TypeError): |
@hroncok , The patch looks great. Please could you open a PR? |
There are two changes: Changes in the actual code: - _member_names changed from a list to a dict in python/cpython#28907 - we instance-check and remove by list-specific or dict-specific way Change in the tests only: - accessing other enum members via instance attributes is no longer possible - we access them via the class instead - we leave the original test in a try-except block Some of the Python enum changes might get reverted, see python/cpython#93910 But the fix is backwards compatible. Fixes googleapis#326
* Adjust to enum changes in Python 3.11.0b3 There are two changes: Changes in the actual code: - _member_names changed from a list to a dict in python/cpython#28907 - we instance-check and remove by list-specific or dict-specific way Change in the tests only: - accessing other enum members via instance attributes is no longer possible - we access them via the class instead - we leave the original test in a try-except block Some of the Python enum changes might get reverted, see python/cpython#93910 But the fix is backwards compatible. Fixes #326 * ci: unit test session with python 3.11.0-beta.3 * ci: add python v3.11.0-beta.3 to noxfile.py * another attempt to get python 3.11.0b3 working in github actions * ci: use python 3.8 for docs check * ci: fix docs build * fix ci * mark python 3.11 tests as required * add python 3.11 to setup.py * fix docs build * remove python 3.11 test for unitcpp * remove python 3.11 test for unitcpp * remove python 3.11 test for unitcpp * attempt to fix exclude in github action Co-authored-by: Anthonios Partheniou <[email protected]>
Environment details
Python
Fedora 37 (rawhide)
Python 3.11.0b3
v1.20.6
Steps to reproduce
pytest
in Python 3.11.0b3The first failure appears in
test_total_ordering_w_other_enum_type
:The second is in
test_enum_alias_good
:For the second one, one of my coworkers found that
_member_names
is now adict
from a recent PR.The text was updated successfully, but these errors were encountered: