Skip to content

Commit

Permalink
fix: lookup attribute instead of performing a deepcopy (#226)
Browse files Browse the repository at this point in the history
* fix: lookup attribute instead of performing a deepcopy

* address review feedback

Co-authored-by: Anthonios Partheniou <[email protected]>
  • Loading branch information
GabrieleMazzola and parthea authored May 2, 2022
1 parent 3148a1c commit e469059
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion proto/marshal/collections/repeated.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ def _pb_type(self):
if len(self.pb) > 0:
return type(self.pb[0])

# We have no members in the list.
# We have no members in the list, so we get the type from the attributes.
if hasattr(self.pb, "_message_descriptor") and hasattr(
self.pb._message_descriptor, "_concrete_class"
):
return self.pb._message_descriptor._concrete_class

# Fallback logic in case attributes are not available
# In order to get the type, we create a throw-away copy and add a
# blank member to it.
canary = copy.deepcopy(self.pb).add()
Expand Down

0 comments on commit e469059

Please sign in to comment.