Skip to content

refactor: extract common logic to TableBase class #956

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

Merged
merged 8 commits into from
Sep 17, 2021

Conversation

plamut
Copy link
Contributor

@plamut plamut commented Sep 9, 2021

Closes #871.

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 a review from a team September 9, 2021 08:55
@plamut plamut requested a review from a team as a code owner September 9, 2021 08:55
@plamut plamut requested a review from tswast September 9, 2021 08:55
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Sep 9, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 9, 2021
@@ -126,45 +127,93 @@ def _view_use_legacy_sql_getter(table):
return True


class TableReference(object):
"""TableReferences are pointers to tables.
class TableBase:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's either make this private (_TableBase) or document it + update relevant types in the client module.

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 don't see the end users using TableBase directly, it just serves as a central place where we keep the common functionality. An implementation detail, in other words.

Let's mark it as private.

Copy link
Contributor

Choose a reason for hiding this comment

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

The contrarian point is that parameter types might use a public TableBase to signal the minimal contract that their arguments require, which is more focused than Union[Table, TableRef, ...]. I don't see any case where TableBase as a return type make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some thought I'm leaning towards keeping the base class private if the main reason for making it public is cleaner type annotations. I view type annotations more as an optional helper, and not as an end goal that would require adjusting the code just for the annotations' sake. As a bonus we still have an option to define our own TableType alias if we don't like Union[Table, ...].

Or does anybody have a strong contrary opinion here?

@plamut plamut requested review from tseaver and tswast September 15, 2021 14:49
@plamut plamut added the automerge Merge the pull request once unit tests and other checks pass. label Sep 17, 2021
@plamut plamut merged commit afdc1ed into googleapis:main Sep 17, 2021
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Sep 17, 2021
@plamut plamut deleted the iss-871 branch September 17, 2021 08:39
abdelmegahedgoogle pushed a commit to abdelmegahedgoogle/python-bigquery that referenced this pull request Apr 17, 2023
* refactor: extract common logic to TableBase class

* Adress pytype's missing attribute false warning

* Mark TableBase class as private

* Simplify TableReference.to_api_repr() logic

* Avoid get/set subproperty helper gotcha

* Test _TableBase class directly
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
Development

Successfully merging this pull request may close these issues.

Extract common features of Table* classes to a new base class
3 participants