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: Add support for Python 3.11 #329

Merged
merged 18 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions proto/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ def __new__(mcls, name, bases, attrs):
# 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(
Expand Down
6 changes: 5 additions & 1 deletion tests/test_enum_total_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

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

to_compare is already OneEnum.SOME_VALUE -- so what is the purpose of the indirect reference through itself? Can this part of the test just be dropped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this entire assertion here seemed redundant to me as well, but I decided to keep testing what was tested.

Note that I am not available to fine-tune this into perfection, that's why I posted the patch in a comment initially as "this makes it pass" instead of opening a PR right away.

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):
Expand Down