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!: avoid collision with built-in functions by renaming type property to type_ #316

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.6/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ env_vars: {
value: "py-3.6"
}

# Declare build specific Cloud project.
env_vars: {
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
value: "python-docs-samples-tests-py36"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-bigquery/.kokoro/test-samples.sh"
Expand Down
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.7/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ env_vars: {
value: "py-3.7"
}

# Declare build specific Cloud project.
env_vars: {
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
value: "python-docs-samples-tests-py37"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-bigquery/.kokoro/test-samples.sh"
Expand Down
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.8/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ env_vars: {
value: "py-3.8"
}

# Declare build specific Cloud project.
env_vars: {
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
value: "python-docs-samples-tests-py38"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-bigquery/.kokoro/test-samples.sh"
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigquery/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def to_standard_sql(self):
field.to_standard_sql() for field in self.fields
)

return types.StandardSqlField(name=self.name, type=sql_type)
return types.StandardSqlField(name=self.name, type_=sql_type)

def __eq__(self, other):
if not isinstance(other, SchemaField):
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/bigquery_v2/types/standard_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class StandardSqlField(proto.Message):
name (str):
Optional. The name of this field. Can be
absent for struct fields.
type (~.standard_sql.StandardSqlDataType):
type_ (~.standard_sql.StandardSqlDataType):
Optional. The type of this parameter. Absent
if not explicitly specified (e.g., CREATE
FUNCTION statement can omit the return type; in
Expand All @@ -89,7 +89,7 @@ class StandardSqlField(proto.Message):

name = proto.Field(proto.STRING, number=1)

type = proto.Field(proto.MESSAGE, number=2, message=StandardSqlDataType,)
type_ = proto.Field(proto.MESSAGE, number=2, message=StandardSqlDataType,)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, this is a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From talking on the Yoshi Python Chat, we have to take this :-(

Just added a commit that handles the rename in to_standard_sql



class StandardSqlStructType(proto.Message):
Expand Down
7 changes: 3 additions & 4 deletions synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/python-bigquery.git",
"sha": "31644d380b35a76a9147801a4b6b0271c246fd0c"
"sha": "35627d145a41d57768f19d4392ef235928e00f72"
}
},
{
Expand All @@ -19,14 +19,14 @@
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "f3c04883d6c43261ff13db1f52d03a283be06871"
"sha": "9b0da5204ab90bcc36f8cd4e5689eff1a54cc3e4"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "f3c04883d6c43261ff13db1f52d03a283be06871"
"sha": "9b0da5204ab90bcc36f8cd4e5689eff1a54cc3e4"
}
}
],
Expand Down Expand Up @@ -112,7 +112,6 @@
"samples/AUTHORING_GUIDE.md",
"samples/CONTRIBUTING.md",
"scripts/decrypt-secrets.sh",
"scripts/fixup_bigquery_v2_keywords.py",
"scripts/readme-gen/readme_gen.py",
"scripts/readme-gen/templates/README.tmpl.rst",
"scripts/readme-gen/templates/auth.tmpl.rst",
Expand Down
32 changes: 16 additions & 16 deletions tests/unit/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_to_standard_sql_simple_type(self):
field = self._make_one("some_field", legacy_type)
standard_field = field.to_standard_sql()
self.assertEqual(standard_field.name, "some_field")
self.assertEqual(standard_field.type.type_kind, standard_type)
self.assertEqual(standard_field.type_.type_kind, standard_type)

def test_to_standard_sql_struct_type(self):
from google.cloud.bigquery_v2 import types
Expand Down Expand Up @@ -258,28 +258,28 @@ def test_to_standard_sql_struct_type(self):

# level 2 fields
sub_sub_field_date = types.StandardSqlField(
name="date_field", type=sql_type(type_kind=sql_type.TypeKind.DATE)
name="date_field", type_=sql_type(type_kind=sql_type.TypeKind.DATE)
)
sub_sub_field_time = types.StandardSqlField(
name="time_field", type=sql_type(type_kind=sql_type.TypeKind.TIME)
name="time_field", type_=sql_type(type_kind=sql_type.TypeKind.TIME)
)

# level 1 fields
sub_field_struct = types.StandardSqlField(
name="last_used", type=sql_type(type_kind=sql_type.TypeKind.STRUCT)
name="last_used", type_=sql_type(type_kind=sql_type.TypeKind.STRUCT)
)
sub_field_struct.type.struct_type.fields.extend(
sub_field_struct.type_.struct_type.fields.extend(
[sub_sub_field_date, sub_sub_field_time]
)
sub_field_bytes = types.StandardSqlField(
name="image_content", type=sql_type(type_kind=sql_type.TypeKind.BYTES)
name="image_content", type_=sql_type(type_kind=sql_type.TypeKind.BYTES)
)

# level 0 (top level)
expected_result = types.StandardSqlField(
name="image_usage", type=sql_type(type_kind=sql_type.TypeKind.STRUCT)
name="image_usage", type_=sql_type(type_kind=sql_type.TypeKind.STRUCT)
)
expected_result.type.struct_type.fields.extend(
expected_result.type_.struct_type.fields.extend(
[sub_field_bytes, sub_field_struct]
)

Expand Down Expand Up @@ -307,7 +307,7 @@ def test_to_standard_sql_array_type_simple(self):
expected_sql_type = sql_type(type_kind=sql_type.TypeKind.ARRAY)
expected_sql_type.array_element_type.type_kind = sql_type.TypeKind.INT64
expected_result = types.StandardSqlField(
name="valid_numbers", type=expected_sql_type
name="valid_numbers", type_=expected_sql_type
)

# construct "repeated" SchemaField object and convert to standard SQL
Expand All @@ -323,22 +323,22 @@ def test_to_standard_sql_array_type_struct(self):

# define person STRUCT
name_field = types.StandardSqlField(
name="name", type=sql_type(type_kind=sql_type.TypeKind.STRING)
name="name", type_=sql_type(type_kind=sql_type.TypeKind.STRING)
)
age_field = types.StandardSqlField(
name="age", type=sql_type(type_kind=sql_type.TypeKind.INT64)
name="age", type_=sql_type(type_kind=sql_type.TypeKind.INT64)
)
person_struct = types.StandardSqlField(
name="person_info", type=sql_type(type_kind=sql_type.TypeKind.STRUCT)
name="person_info", type_=sql_type(type_kind=sql_type.TypeKind.STRUCT)
)
person_struct.type.struct_type.fields.extend([name_field, age_field])
person_struct.type_.struct_type.fields.extend([name_field, age_field])

# define expected result - an ARRAY of person structs
expected_sql_type = sql_type(
type_kind=sql_type.TypeKind.ARRAY, array_element_type=person_struct.type
type_kind=sql_type.TypeKind.ARRAY, array_element_type=person_struct.type_
)
expected_result = types.StandardSqlField(
name="known_people", type=expected_sql_type
name="known_people", type_=expected_sql_type
)

# construct legacy repeated SchemaField object
Expand All @@ -359,7 +359,7 @@ def test_to_standard_sql_unknown_type(self):

self.assertEqual(standard_field.name, "weird_field")
self.assertEqual(
standard_field.type.type_kind, sql_type.TypeKind.TYPE_KIND_UNSPECIFIED
standard_field.type_.type_kind, sql_type.TypeKind.TYPE_KIND_UNSPECIFIED
)

def test___eq___wrong_type(self):
Expand Down