From 5599f2ceeca9038695113a9e3ea1a576b4fa021c Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 18 Oct 2024 12:19:34 -0700 Subject: [PATCH] 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 --- python/google/protobuf/internal/well_known_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/google/protobuf/internal/well_known_types.py b/python/google/protobuf/internal/well_known_types.py index 4e7c79a91b..0d95b4b982 100644 --- a/python/google/protobuf/internal/well_known_types.py +++ b/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."""