Skip to content

Commit d51ae36

Browse files
airbender-1parthea
andauthored
fix: fix enums initialization in PyPy (#507)
* fix: enums initialization in PyPy When removing the _pb_options name from the enum attributes, enums initialization in PyPy should not raise exception. Refs: #506 * test: add presubmit for PyPy * Add unit (pypy3.10, python) as a required check --------- Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 702eb82 commit d51ae36

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

packages/proto-plus/.github/sync-repo-settings.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ branchProtectionRules:
1919
- 'unit (3.10, cpp)'
2020
- 'unit (3.10, python)'
2121
- 'unit (3.10, upb)'
22+
- 'unit (pypy3.10, python)'
2223
- 'unit (3.11, python)'
2324
- 'unit (3.11, upb)'
2425
- 'unit (3.12, python)'

packages/proto-plus/.github/workflows/tests.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ jobs:
4242
runs-on: ubuntu-22.04
4343
strategy:
4444
matrix:
45-
python: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
45+
# See https://github.com/actions/setup-python?tab=readme-ov-file#basic-usage
46+
# for the format of the entries in 'python'.
47+
# See https://downloads.python.org/pypy/ for the current supported versions of PyPy.
48+
python: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', 'pypy3.10']
4649
variant: ['cpp', 'python', 'upb']
4750
# TODO(https://github.com/googleapis/proto-plus-python/issues/389):
4851
# Remove the 'cpp' implementation once support for Protobuf 3.x is dropped.
@@ -56,6 +59,14 @@ jobs:
5659
python: 3.12
5760
- variant: "cpp"
5861
python: 3.13
62+
# In PyPy 3.10, we see the following warning
63+
# UserWarning: Selected implementation upb is not available. Falling back to the python implementation.
64+
- variant: "upb"
65+
python: 'pypy3.10'
66+
# In PyPy 3.10, we see the following warning
67+
# UserWarning: PyPy does not work yet with cpp protocol buffers. Falling back to the python implementation.
68+
- variant: "cpp"
69+
python: 'pypy3.10'
5970
steps:
6071
- uses: actions/checkout@v4
6172
- name: Set up Python ${{ matrix.python }}
@@ -66,22 +77,16 @@ jobs:
6677
- name: Install nox
6778
run: |
6879
pip install nox
69-
# Trim the Python version string
70-
- name: Trim python version
71-
run: |
72-
PYTHON_VERSION_TRIMMED=${{ matrix.python }}
73-
PYTHON_VERSION_TRIMMED=$(echo $PYTHON_VERSION_TRIMMED | cut -c1-4)
74-
echo "PYTHON_VERSION_TRIMMED=$PYTHON_VERSION_TRIMMED" >> $GITHUB_ENV
7580
- name: Run unit tests
7681
env:
77-
COVERAGE_FILE: .coverage-${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }}
82+
COVERAGE_FILE: .coverage-${{ matrix.variant }}-${{ matrix.python }}
7883
run: |
79-
nox -s "unit-${{ env.PYTHON_VERSION_TRIMMED }}(implementation='${{ matrix.variant }}')"
84+
nox -s "unit-${{ matrix.python }}(implementation='${{ matrix.variant }}')"
8085
- name: Upload coverage results
8186
uses: actions/upload-artifact@v4
8287
with:
83-
name: coverage-artifact-${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }}
84-
path: .coverage-${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }}
88+
name: coverage-artifact-${{ matrix.variant }}-${{ matrix.python }}
89+
path: .coverage-${{ matrix.variant }}-${{ matrix.python }}
8590
include-hidden-files: true
8691
prerelease:
8792
runs-on: ubuntu-22.04

packages/proto-plus/noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"3.8",
2727
"3.9",
2828
"3.10",
29+
"pypy3.10",
2930
"3.11",
3031
"3.12",
3132
"3.13",

packages/proto-plus/proto/enums.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def __new__(mcls, name, bases, attrs):
6161
if isinstance(attrs._member_names, list):
6262
idx = attrs._member_names.index(pb_options)
6363
attrs._member_names.pop(idx)
64+
elif isinstance(attrs._member_names, set): # PyPy
65+
attrs._member_names.discard(pb_options)
6466
else: # Python 3.11.0b3
6567
del attrs._member_names[pb_options]
6668

packages/proto-plus/testing/constraints-pypy3.10.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)