Skip to content

fix: Add support for Python 3.11 #329

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

Merged
merged 18 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ branchProtectionRules:
- 'unit (3.9)'
- 'unit (3.10, cpp)'
- 'unit (3.10)'
- 'unit (3.11)'
- cover
- OwlBot Post Processor
- 'cla/google'
Expand Down
23 changes: 16 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.9"
- name: Install nox.
run: python -m pip install nox
- name: Build the documentation.
run: nox -s docs
unit:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python: ['3.6', '3.7', '3.8', '3.9', '3.10']
python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
variant: ['', 'cpp', 'upb']
exclude:
- variant: "cpp"
python: 3.11
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python }}
Expand All @@ -53,16 +56,22 @@ jobs:
- name: Install nox
run: |
pip install nox
# Trim the Python version string
- name: Trim python version
run: |
PYTHON_VERSION_TRIMMED=${{ matrix.python }}
PYTHON_VERSION_TRIMMED=$(echo $PYTHON_VERSION_TRIMMED | cut -c1-4)
echo "PYTHON_VERSION_TRIMMED=$PYTHON_VERSION_TRIMMED" >> $GITHUB_ENV
- name: Run unit tests
env:
COVERAGE_FILE: .coverage-${{ matrix.variant }}-${{ matrix.python }}
COVERAGE_FILE: .coverage-${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }}
run: |
nox -s unit${{ matrix.variant }}-${{ matrix.python }}
nox -s unit${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }}
- name: Upload coverage results
uses: actions/upload-artifact@v3
with:
name: coverage-artifacts
path: .coverage-${{ matrix.variant }}-${{ matrix.python }}
path: .coverage-${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }}
cover:
runs-on: ubuntu-latest
needs:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
9 changes: 6 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
"3.8",
"3.9",
"3.10",
"3.11",
]

# Error if a python version is missing
nox.options.error_on_missing_interpreters = True


@nox.session(python=PYTHON_VERSIONS)
def unit(session, proto="python"):
Expand Down Expand Up @@ -64,7 +68,7 @@ def unit(session, proto="python"):
# Check if protobuf has released wheels for new python versions
# https://pypi.org/project/protobuf/#files
# This list will generally be shorter than 'unit'
@nox.session(python=PYTHON_VERSIONS)
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"])
def unitcpp(session):
return unit(session, proto="cpp")

Expand All @@ -74,8 +78,7 @@ def unitupb(session):
return unit(session, proto="upb")


# Just use the most recent version for docs
@nox.session(python=PYTHON_VERSIONS[-1])
@nox.session(python="3.9")
def docs(session):
"""Build the docs."""

Expand Down
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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Code Generators",
"Topic :: Software Development :: Libraries :: Python Modules",
],
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