Skip to content

Commit 1b976a1

Browse files
authored
chore(proto-plus): update Python version and clean up enums.py (#16912)
This PR updates `proto-plus` to establish Python 3.10 as the minimum supported version, dropping support for Python 3.9 and below. ### Changes * Configuration: Updated `pyproject.toml` and `noxfile.py` to require Python 3.10+ and remove references to Python 3.9. * Code: Refactored `repeated.py` to use the walrus operator (PEP 572). Documentation: Updated a traceback example in `docs/fields.rst` to reference Python 3.10. * Cleanup: Replaced a stale comment regarding Python 3.7 features in proto/enums.py with a tracked TODO referencing Issue #16911. > [!note] > Also includes a conditional in the `run_single_test.sh` file to manage the chicken OR the egg problem of managing failing tests when a `unit-3.9` nox session is not present. Because we are migrating handwritten libs one at a time, we are in a transition period were we must still test for 3.9 in libraries that still support it but cannot have a failing presubmit in libraries that don't support it. ### Blocking - [x] This PR is blocked by PR #16910
1 parent 1e4f3a7 commit 1b976a1

6 files changed

Lines changed: 12 additions & 10 deletions

File tree

ci/run_single_test.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ case ${TEST_TYPE} in
7171
unit)
7272
case ${PY_VERSION} in
7373
"3.9")
74-
nox -s unit-3.9
75-
retval=$?
74+
if nox --list-sessions | grep -q "unit-3.9"; then
75+
nox -s unit-3.9
76+
retval=$?
77+
else
78+
echo "Skipping unit-3.9 as it is not supported by this package."
79+
retval=0
80+
fi
7681
;;
7782
"3.10")
7883
nox -s unit-3.10

packages/proto-plus/docs/fields.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Declare them in Python using the :class:`~.RepeatedField` class:
8181
>>> row.values = [struct_pb2.Value(string_value="hello")]
8282
Traceback (most recent call last):
8383
File "<stdin>", line 1, in <module>
84-
File "/usr/local/google/home/busunkim/github/python-automl/.nox/unit-3-8/lib/python3.8/site-packages/proto/message.py", line 543, in __setattr__
84+
File "/usr/local/google/home/busunkim/github/python-automl/.nox/unit-3-10/lib/python3.10/site-packages/proto/message.py", line 543, in __setattr__
8585
self._pb.MergeFrom(self._meta.pb(**{key: pb_value}))
8686
TypeError: Value must be iterable
8787

packages/proto-plus/noxfile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
DEFAULT_PYTHON_VERSION = "3.14"
3232

3333
PYTHON_VERSIONS = [
34-
"3.9",
3534
"3.10",
3635
"3.11",
3736
"3.12",

packages/proto-plus/proto/enums.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def __new__(mcls, name, bases, attrs):
5555
opts = attrs.pop(pb_options, {})
5656
# This is the only portable way to remove the _pb_options name
5757
# from the enum attrs.
58-
# In 3.7 onwards, we can define an _ignore_ attribute and do some
59-
# mucking around with that.
58+
# TODO: Use _ignore_ attribute to ignore _pb_options (Issue #16911)
6059
if pb_options in attrs._member_names:
6160
if isinstance(attrs._member_names, list):
6261
idx = attrs._member_names.index(pb_options)

packages/proto-plus/proto/marshal/collections/repeated.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ def __setitem__(self, key, value):
166166
else: # Is an extended slice.
167167
indices = range(start, stop, step)
168168

169-
if len(value) != len(indices): # XXX: Use PEP 572 on 3.8+
169+
if (v_len := len(value)) != len(indices):
170170
raise ValueError(
171171
f"attempt to assign sequence of size "
172-
f"{len(value)} to extended slice of size "
172+
f"{v_len} to extended slice of size "
173173
f"{len(indices)}"
174174
)
175175

packages/proto-plus/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ build-backend = "setuptools.build_meta"
2020
name = "proto-plus"
2121
authors = [{ name = "Google LLC", email = "googleapis-packages@google.com" }]
2222
license = { text = "Apache 2.0" }
23-
requires-python = ">=3.9"
23+
requires-python = ">=3.10"
2424
description = "Beautiful, Pythonic protocol buffers"
2525
readme = "README.rst"
2626
classifiers = [
@@ -29,7 +29,6 @@ classifiers = [
2929
"License :: OSI Approved :: Apache Software License",
3030
"Programming Language :: Python",
3131
"Programming Language :: Python :: 3",
32-
"Programming Language :: Python :: 3.9",
3332
"Programming Language :: Python :: 3.10",
3433
"Programming Language :: Python :: 3.11",
3534
"Programming Language :: Python :: 3.12",

0 commit comments

Comments
 (0)