-
Notifications
You must be signed in to change notification settings - Fork 298
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
Run mypy (and pytype?) on code samples #1074
Comments
@plamut I kinda consider this a v3 blocker. I'd really like to make sure our type hints are working from the end-user perspective before we start publishing them. |
@tswast OK, I can start working on this as soon as I'm done with a similar task in Pub/Sub. It's quite tedious there due to a much more dynamic nature of the code and metaprogramming hacks, but I beleive I'll be done soon. |
TIL, there is a But it only checks that annotations are there, not that they actually work. |
LGTM! 🙃 😁 |
Random observation: We need to annotate return types of our For example, when checking the samples with more strict options, the following innocent line resulted in a table = bigquery.Table(table_id) Error:
The following seems to be required to appease diff --git google/cloud/bigquery/table.py google/cloud/bigquery/table.py
index f434688..5b96369 100644
--- google/cloud/bigquery/table.py
+++ google/cloud/bigquery/table.py
@@ -369,7 +369,7 @@ class Table(_TableBase):
"require_partition_filter": "requirePartitionFilter",
}
- def __init__(self, table_ref, schema=None):
+ def __init__(self, table_ref, schema=None) -> "Table":
table_ref = _table_arg_to_table_ref(table_ref)
self._properties = {"tableReference": table_ref.to_api_repr(), "labels": {}}
# Let the @property do validation. I will either do it in the scope of this issue, or in a separate PR if the required changes turn out to be non-trivial. |
Good catch, thanks! A separate PR sounds good to me, since we know the samples changes will at the very least be quite a few lines of code. |
On the other hand... If I apply the workaround suggested above, the I need to figure out why this is the case. Annotating |
I wonder if we'll need to update our samples to use the original location (e.g. |
It turned out that the fix was to explicitly annotate the return type of The error message mentioning "function" was initially somewhat confusing, but I later discovered the true cause of the complaint. It seems that the mentioned change will not be needed. |
Fixed by https://github.com/googleapis/python-bigquery/pull/1081/files#diff-f7a16a65f061822bcc73b8296f4dc837353d379d8d9cc5307982cb6941442835R46 which adds the |
So that we have some assurance that our customers can use mypy / pytype successfully from our library, I think we should run mypy / pytype on them as well.
Ideally we'd do this from the Samples Kokoro jobs, as that'll be more similar to the development environment that a customer has setup.
Step 0.
Step 1.
Step 2.
The text was updated successfully, but these errors were encountered: