Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add types to DatasetReference constructor #1601

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: add types to DatasetReference constructor
  • Loading branch information
karelserruys-foodpairing committed Jul 6, 2023
commit ed2097fc80bb6a1de1e8385d53e3b73e81b471fa
20 changes: 10 additions & 10 deletions google/cloud/bigquery/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class DatasetReference(object):
ValueError: If either argument is not of type ``str``.
"""

def __init__(self, project, dataset_id):
def __init__(self, project: str, dataset_id: str):
if not isinstance(project, str):
raise ValueError("Pass a string for project")
if not isinstance(dataset_id, str):
Expand Down Expand Up @@ -166,15 +166,17 @@ def from_string(
standard SQL format.
"""
output_dataset_id = dataset_id
output_project_id = default_project
parts = _helpers._split_id(dataset_id)

if len(parts) == 1 and not default_project:
raise ValueError(
"When default_project is not set, dataset_id must be a "
"fully-qualified dataset ID in standard SQL format, "
'e.g., "project.dataset_id" got {}'.format(dataset_id)
)
if len(parts) == 1:
if default_project is not None:
output_project_id = default_project
else:
raise ValueError(
"When default_project is not set, dataset_id must be a "
"fully-qualified dataset ID in standard SQL format, "
'e.g., "project.dataset_id" got {}'.format(dataset_id)
)
elif len(parts) == 2:
output_project_id, output_dataset_id = parts
elif len(parts) > 2:
Expand All @@ -183,7 +185,6 @@ def from_string(
"dataset ID in standard SQL format. e.g. "
'"project.dataset_id", got {}'.format(dataset_id)
)

return cls(output_project_id, output_dataset_id)

def to_api_repr(self) -> dict:
Expand Down Expand Up @@ -454,7 +455,6 @@ def __ne__(self, other):
return not self == other

def __repr__(self):

return f"<AccessEntry: role={self.role}, {self._entity_type}={self.entity_id}>"

def _key(self):
Expand Down