From 457da24c15e3f104de51a7c0c402ebf79dcc7389 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Mon, 18 Mar 2019 09:23:47 -0700 Subject: [PATCH] Refactor table() methods into shared implementation. (#7516) The method and docstring for the table() method are identical for Dataset, DatasetReference, and DatasetListItem. This commit moves the implementation to a shared method to reduce code duplication. --- bigquery/google/cloud/bigquery/dataset.py | 49 ++++++++--------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/bigquery/google/cloud/bigquery/dataset.py b/bigquery/google/cloud/bigquery/dataset.py index 9530eac9ee60..2a71c900baf0 100644 --- a/bigquery/google/cloud/bigquery/dataset.py +++ b/bigquery/google/cloud/bigquery/dataset.py @@ -24,6 +24,19 @@ from google.cloud.bigquery.table import TableReference +def _get_table_reference(self, table_id): + """Constructs a TableReference. + + Args: + table_id (str): The ID of the table. + + Returns: + google.cloud.bigquery.table.TableReference: + A table reference for a table in this dataset. + """ + return TableReference(self, table_id) + + class AccessEntry(object): """Represents grant of an access role to an entity. @@ -191,17 +204,7 @@ def path(self): """str: URL path for the dataset based on project and dataset ID.""" return "/projects/%s/datasets/%s" % (self.project, self.dataset_id) - def table(self, table_id): - """Constructs a TableReference. - - Args: - table_id (str): The ID of the table. - - Returns: - google.cloud.bigquery.table.TableReference: - A table reference for a table in this dataset. - """ - return TableReference(self, table_id) + table = _get_table_reference @classmethod def from_api_repr(cls, resource): @@ -578,17 +581,7 @@ def _build_resource(self, filter_fields): return partial - def table(self, table_id): - """Constructs a TableReference. - - Args: - table_id (str): the ID of the table. - - Returns: - google.cloud.bigquery.table.TableReference: - A TableReference for a table in this dataset. - """ - return TableReference(self.reference, table_id) + table = _get_table_reference def __repr__(self): return "Dataset({})".format(repr(self.reference)) @@ -668,14 +661,4 @@ def reference(self): """ return DatasetReference(self.project, self.dataset_id) - def table(self, table_id): - """Constructs a TableReference. - - Args: - table_id (str): the ID of the table. - - Returns: - google.cloud.bigquery.table.TableReference: - A TableReference for a table in this dataset. - """ - return TableReference(self.reference, table_id) + table = _get_table_reference