well_known_types: Use str.rpartition instead of str.split for Any type 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
pull/18130/head
Protobuf Team Bot 5 months ago committed by Copybara-Service
parent 67fca5cb70
commit 5599f2ceec
  1. 2
      python/google/protobuf/internal/well_known_types.py

@ -68,7 +68,7 @@ class Any(object):
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."""

Loading…
Cancel
Save