Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
0c293def
Commit
0c293def
authored
Jul 27, 2010
by
kenton@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue 207
parent
15b675ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
reflection_test.py
python/google/protobuf/internal/reflection_test.py
+13
-0
reflection.py
python/google/protobuf/reflection.py
+9
-1
No files found.
python/google/protobuf/internal/reflection_test.py
View file @
0c293def
...
...
@@ -1035,6 +1035,19 @@ class ReflectionTest(unittest.TestCase):
self
.
assertEqual
(
222
,
ext2
[
1
]
.
bb
)
self
.
assertEqual
(
333
,
ext2
[
2
]
.
bb
)
def
testMergeFromBug
(
self
):
message1
=
unittest_pb2
.
TestAllTypes
()
message2
=
unittest_pb2
.
TestAllTypes
()
# Cause optional_nested_message to be instantiated within message1, even
# though it is not considered to be "present".
message1
.
optional_nested_message
self
.
assertFalse
(
message1
.
HasField
(
'optional_nested_message'
))
# Merge into message2. This should not instantiate the field is message2.
message2
.
MergeFrom
(
message1
)
self
.
assertFalse
(
message2
.
HasField
(
'optional_nested_message'
))
def
testCopyFromSingularField
(
self
):
# Test copy with just a singular field.
proto1
=
unittest_pb2
.
TestAllTypes
()
...
...
python/google/protobuf/reflection.py
View file @
0c293def
...
...
@@ -943,13 +943,21 @@ def _AddMergeFromMethod(cls):
fields
=
self
.
_fields
for
field
,
value
in
msg
.
_fields
.
iteritems
():
if
field
.
label
==
LABEL_REPEATED
or
field
.
cpp_type
==
CPPTYPE_MESSAGE
:
if
field
.
label
==
LABEL_REPEATED
:
field_value
=
fields
.
get
(
field
)
if
field_value
is
None
:
# Construct a new object to represent this field.
field_value
=
field
.
_default_constructor
(
self
)
fields
[
field
]
=
field_value
field_value
.
MergeFrom
(
value
)
elif
field
.
cpp_type
==
CPPTYPE_MESSAGE
:
if
value
.
_is_present_in_parent
:
field_value
=
fields
.
get
(
field
)
if
field_value
is
None
:
# Construct a new object to represent this field.
field_value
=
field
.
_default_constructor
(
self
)
fields
[
field
]
=
field_value
field_value
.
MergeFrom
(
value
)
else
:
self
.
_fields
[
field
]
=
value
cls
.
MergeFrom
=
MergeFrom
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment