diff --git a/google/cloud/pubsublite/types/paths.py b/google/cloud/pubsublite/types/paths.py index 9038180a..3901afac 100644 --- a/google/cloud/pubsublite/types/paths.py +++ b/google/cloud/pubsublite/types/paths.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import NamedTuple +from typing import NamedTuple, Union from google.api_core.exceptions import InvalidArgument @@ -20,23 +20,23 @@ class LocationPath(NamedTuple): - project_number: int + project: Union[int, str] location: CloudZone def __str__(self): - return f"projects/{self.project_number}/locations/{self.location}" + return f"projects/{self.project}/locations/{self.location}" class TopicPath(NamedTuple): - project_number: int + project: Union[int, str] location: CloudZone name: str def __str__(self): - return f"projects/{self.project_number}/locations/{self.location}/topics/{self.name}" + return f"projects/{self.project}/locations/{self.location}/topics/{self.name}" def to_location_path(self): - return LocationPath(self.project_number, self.location) + return LocationPath(self.project, self.location) @staticmethod def parse(to_parse: str) -> "TopicPath": @@ -51,27 +51,19 @@ def parse(to_parse: str) -> "TopicPath": "Topic path must be formatted like projects/{project_number}/locations/{location}/topics/{name} but was instead " + to_parse ) - project_number: int - try: - project_number = int(splits[1]) - except ValueError: - raise InvalidArgument( - "Topic path must be formatted like projects/{project_number}/locations/{location}/topics/{name} but was instead " - + to_parse - ) - return TopicPath(project_number, CloudZone.parse(splits[3]), splits[5]) + return TopicPath(splits[1], CloudZone.parse(splits[3]), splits[5]) class SubscriptionPath(NamedTuple): - project_number: int + project: Union[int, str] location: CloudZone name: str def __str__(self): - return f"projects/{self.project_number}/locations/{self.location}/subscriptions/{self.name}" + return f"projects/{self.project}/locations/{self.location}/subscriptions/{self.name}" def to_location_path(self): - return LocationPath(self.project_number, self.location) + return LocationPath(self.project, self.location) @staticmethod def parse(to_parse: str) -> "SubscriptionPath": @@ -86,12 +78,4 @@ def parse(to_parse: str) -> "SubscriptionPath": "Subscription path must be formatted like projects/{project_number}/locations/{location}/subscriptions/{name} but was instead " + to_parse ) - project_number: int - try: - project_number = int(splits[1]) - except ValueError: - raise InvalidArgument( - "Subscription path must be formatted like projects/{project_number}/locations/{location}/subscriptions/{name} but was instead " - + to_parse - ) - return SubscriptionPath(project_number, CloudZone.parse(splits[3]), splits[5]) + return SubscriptionPath(splits[1], CloudZone.parse(splits[3]), splits[5]) diff --git a/samples/snippets/quickstart_test.py b/samples/snippets/quickstart_test.py index 499f0db5..470ca32f 100644 --- a/samples/snippets/quickstart_test.py +++ b/samples/snippets/quickstart_test.py @@ -73,7 +73,7 @@ def test_create_lite_topic_example(topic_path, capsys): topic_path_object = TopicPath.parse(topic_path) create_lite_topic_example.create_lite_topic( - topic_path_object.project_number, + topic_path_object.project, topic_path_object.location.region.name, topic_path_object.location.zone_id, topic_path_object.name, @@ -88,7 +88,7 @@ def test_update_lite_topic_example(topic_path, capsys): topic_path_object = TopicPath.parse(topic_path) update_lite_topic_example.update_lite_topic( - topic_path_object.project_number, + topic_path_object.project, topic_path_object.location.region.name, topic_path_object.location.zone_id, topic_path_object.name, @@ -102,7 +102,7 @@ def test_get_lite_topic_example(topic_path, capsys): topic_path_object = TopicPath.parse(topic_path) get_lite_topic_example.get_lite_topic( - topic_path_object.project_number, + topic_path_object.project, topic_path_object.location.region.name, topic_path_object.location.zone_id, topic_path_object.name, @@ -116,7 +116,7 @@ def test_list_lite_topics_example(topic_path, capsys): topic_path_object = TopicPath.parse(topic_path) list_lite_topics_example.list_lite_topics( - topic_path_object.project_number, + topic_path_object.project, topic_path_object.location.region.name, topic_path_object.location.zone_id, ) @@ -131,7 +131,7 @@ def test_create_lite_subscription(subscription_path, topic_path, capsys): topic_path_object = TopicPath.parse(topic_path) create_lite_subscription_example.create_lite_subscription( - subscription_path_object.project_number, + subscription_path_object.project, subscription_path_object.location.region.name, subscription_path_object.location.zone_id, topic_path_object.name, @@ -147,7 +147,7 @@ def test_update_lite_subscription_example(subscription_path, capsys): subscription_path_object = SubscriptionPath.parse(subscription_path) update_lite_subscription_example.update_lite_subscription( - subscription_path_object.project_number, + subscription_path_object.project, subscription_path_object.location.region.name, subscription_path_object.location.zone_id, subscription_path_object.name, @@ -162,7 +162,7 @@ def test_get_lite_subscription(subscription_path, capsys): subscription_path_object = SubscriptionPath.parse(subscription_path) get_lite_subscription_example.get_lite_subscription( - subscription_path_object.project_number, + subscription_path_object.project, subscription_path_object.location.region.name, subscription_path_object.location.zone_id, subscription_path_object.name, @@ -177,7 +177,7 @@ def test_list_lite_subscriptions_in_project(subscription_path, capsys): subscription_path_object = SubscriptionPath.parse(subscription_path) list_lite_subscriptions_in_project_example.list_lite_subscriptions_in_project( - subscription_path_object.project_number, + subscription_path_object.project, subscription_path_object.location.region.name, subscription_path_object.location.zone_id, ) @@ -192,7 +192,7 @@ def test_list_lite_subscriptions_in_topic(topic_path, subscription_path, capsys) topic_path_object = TopicPath.parse(topic_path) list_lite_subscriptions_in_topic_example.list_lite_subscriptions_in_topic( - subscription_path_object.project_number, + subscription_path_object.project, subscription_path_object.location.region.name, subscription_path_object.location.zone_id, topic_path_object.name, @@ -267,7 +267,7 @@ def test_delete_lite_subscription_example(subscription_path, capsys): @backoff.on_exception(backoff.expo, AssertionError, max_time=MAX_TIME) def eventually_consistent_test(): delete_lite_subscription_example.delete_lite_subscription( - subscription_path_object.project_number, + subscription_path_object.project, subscription_path_object.location.region.name, subscription_path_object.location.zone_id, subscription_path_object.name, @@ -286,7 +286,7 @@ def test_delete_lite_topic_example(topic_path, capsys): @backoff.on_exception(backoff.expo, AssertionError, max_time=MAX_TIME) def eventually_consistent_test(): delete_lite_topic_example.delete_lite_topic( - topic_path_object.project_number, + topic_path_object.project, topic_path_object.location.region.name, topic_path_object.location.zone_id, topic_path_object.name,