Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit eb99b25

Browse files
authored
Merge branch 'master' into 270-test-minimum-protobuf-version
2 parents 7e412d0 + f35b77e commit eb99b25

4 files changed

Lines changed: 62 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
### [1.19.7](https://www.github.com/googleapis/proto-plus-python/compare/v1.19.6...v1.19.7) (2021-10-27)
4+
5+
6+
### Bug Fixes
7+
8+
* restore allowing None as value for stringy ints ([#272](https://www.github.com/googleapis/proto-plus-python/issues/272)) ([a8991d7](https://www.github.com/googleapis/proto-plus-python/commit/a8991d71ff455093fbfef142f9140d3f2928195f))
9+
310
### [1.19.6](https://www.github.com/googleapis/proto-plus-python/compare/v1.19.5...v1.19.6) (2021-10-25)
411

512

proto/marshal/rules/stringy_numbers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def to_python(self, value, *, absent: bool = None):
3131
return value
3232

3333
def to_proto(self, value):
34-
return self._python_type(value)
34+
if value is not None:
35+
return self._python_type(value)
36+
37+
return None
3538

3639

3740
class Int64Rule(StringyNumberRule):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from setuptools import find_packages, setup
1919

20-
version = "1.19.6"
20+
version = "1.19.7"
2121

2222
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
2323

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import pytest
16+
17+
from proto.marshal.marshal import BaseMarshal
18+
from proto.primitives import ProtoType
19+
20+
INT_32BIT_PLUS_ONE = 0xFFFFFFFF + 1
21+
22+
23+
@pytest.mark.parametrize(
24+
"pb_type,value,expected",
25+
[
26+
(ProtoType.INT64, 0, 0),
27+
(ProtoType.INT64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE),
28+
(ProtoType.SINT64, -INT_32BIT_PLUS_ONE, -INT_32BIT_PLUS_ONE),
29+
(ProtoType.INT64, None, None),
30+
(ProtoType.UINT64, 0, 0),
31+
(ProtoType.UINT64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE),
32+
(ProtoType.UINT64, None, None),
33+
(ProtoType.SINT64, 0, 0),
34+
(ProtoType.SINT64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE),
35+
(ProtoType.SINT64, -INT_32BIT_PLUS_ONE, -INT_32BIT_PLUS_ONE),
36+
(ProtoType.SINT64, None, None),
37+
(ProtoType.FIXED64, 0, 0),
38+
(ProtoType.FIXED64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE),
39+
(ProtoType.FIXED64, -INT_32BIT_PLUS_ONE, -INT_32BIT_PLUS_ONE),
40+
(ProtoType.FIXED64, None, None),
41+
(ProtoType.SFIXED64, 0, 0),
42+
(ProtoType.SFIXED64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE),
43+
(ProtoType.SFIXED64, -INT_32BIT_PLUS_ONE, -INT_32BIT_PLUS_ONE),
44+
(ProtoType.SFIXED64, None, None),
45+
],
46+
)
47+
def test_marshal_to_proto_stringy_numbers(pb_type, value, expected):
48+
49+
marshal = BaseMarshal()
50+
assert marshal.to_proto(pb_type, value) == expected

0 commit comments

Comments
 (0)