Skip to content

Commit

Permalink
well_known_types: Use str.rpartition instead of str.split for Any typ…
Browse files Browse the repository at this point in the history
…e name

`Any.TypeName` used `str.split` to extract the second part of the type URL
(potentially the only if there's no slash). `str.rpartition` has the same
effect and avoids constructing a list.

PiperOrigin-RevId: 687385575
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Oct 18, 2024
1 parent 67fca5c commit 5599f2c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion python/google/protobuf/internal/well_known_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def Unpack(self, msg):
def TypeName(self):
"""Returns the protobuf type name of the inner message."""
# Only last part is to be used: b/25630112
return self.type_url.split('/')[-1]
return self.type_url.rpartition('/')[2]

def Is(self, descriptor):
"""Checks if this Any represents the given protobuf type."""
Expand Down

0 comments on commit 5599f2c

Please sign in to comment.