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

feat: add with_name() to ScalarQueryParameterType #644

Merged
merged 2 commits into from
May 5, 2021

Conversation

plamut
Copy link
Contributor

@plamut plamut commented May 3, 2021

Fixes #642.

PR checklist:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@plamut plamut requested review from tswast and a team May 3, 2021 11:58
@plamut plamut requested a review from a team as a code owner May 3, 2021 11:58
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label May 3, 2021
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label May 3, 2021
Copy link
Contributor

@jimfulton jimfulton left a comment

Choose a reason for hiding this comment

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

I don't think name should be optional. :)

Also, omitting the name is untested, but easily fixed by making it required.

@@ -119,6 +120,18 @@ def to_api_repr(self):
# attributes in the API representation when needed. Here we omit them.
return {"type": self._type}

def with_name(self, new_name: Optional[str]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why make name optional?

Copy link
Contributor Author

@plamut plamut May 4, 2021

Choose a reason for hiding this comment

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

We allow explicit None to be consistent with the constructor that also accepts None. Perhaps using the alternative form Union[str, None] would make it less confusing, as the argument itself is not optional (to allow clearing the name).

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right that the argument is required. But I still don't see a point in allowing None. Nameless types are readily available in SqlParameterScalarTypes. To expect someone to call with_name and, you know, not provide a name seems silly. :)

I don't think changing Optional[str] to Union[str, None] is an improvement.

I'm willing to defer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tend to not assume about the users' use cases too much, as several times in the past we have gotten that wrong. :)

I don't feel strongly about either way (supporting or not supporting clearing the name), but since the maintenance burden is more or less the same for both options, supporting None seems fine here.

@plamut plamut requested a review from jimfulton May 4, 2021 08:03
Copy link
Contributor

@jimfulton jimfulton left a comment

Choose a reason for hiding this comment

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

Reluctantly.

@plamut plamut merged commit 6cc6876 into googleapis:master May 5, 2021
@plamut plamut deleted the iss-642 branch May 5, 2021 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
2 participants