Skip to content

Commit

Permalink
improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Feb 14, 2022
1 parent 4de2462 commit 7a347b1
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions proto/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,20 @@ def __init__(
# coerced.
marshal = self._meta.marshal
for key, value in mapping.items():
# Underscores may be appended to field names
# that collide with python or proto-plus keywords.
# In case a key only exists with a `_` suffix, coerce the key
# to include the `_` suffix. Is not possible to
# natively define the same field with a trailing underscore in protobuf.
# See related issue
# https://github.com/googleapis/python-api-core/issues/227
if key not in self._meta.fields and f"{key}_" in self._meta.fields:
key = f"{key}_"

try:
pb_type = self._meta.fields[key].pb_type
except KeyError:
# Underscores may be appended to field names
# that collide with python or proto-plus keywords.
# In case a key only exists with a `_` suffix, coerce the key
# to include the `_` suffix. Is not possible to
# natively define the same field with a trailing underscore in protobuf.
# See related issue
# https://github.com/googleapis/python-api-core/issues/227
if f"{key}_" in self._meta.fields:
pb_type = self._meta.fields[f"{key}_"].pb_type
continue

if ignore_unknown_fields:
continue

Expand Down

0 comments on commit 7a347b1

Please sign in to comment.