Skip to content

Commit

Permalink
process: make mypy happy with type annotations (#1036)
Browse files Browse the repository at this point in the history
* process: add mypy types check to nox sessions

* Ignore type errors for not annotated modules

Several dependencies lack type annotations, or they don't advertise
themselves as type-annotated. We do not want `mypy` to complain about
these.

* Fix mypy complaints (batch 1)

* Fix mypy complaints (batch 2)

* Fix mypy complaints (batch 3)

* Fix mypy false positive errors

* Simplify external config options instantiation

* Do not ignore api-core in type checks

More recent releases of google-api-core have typing enabled.

* Remove unneeded __hash__ = None lines

* Use an alias for timeout type in client.py

* Fix PathLike subscription error in pre-Python 3.9

* Fix a typo in docstring

Co-authored-by: Tim Swast <swast@google.com>

* Add mypy to the list of nox sessions to run

* Fix opentelemetry type error

The Opentelemetry APi has changed from the minimum version the
BigQuery client currently uses, we thus need to bound the maximum
Opentelemetry version.

In addition, that maximum version does not yet support type checks, thus
it is ignored.

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Exclude type-checking code from coverage

* Fix patching opentelemetry tracer pvoider

* Adjust get_job() return type, ignore opentelemetry

Co-authored-by: Tim Swast <swast@google.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 8, 2021
1 parent 4616cd5 commit 66b3dd9
Show file tree
Hide file tree
Showing 23 changed files with 220 additions and 182 deletions.
2 changes: 1 addition & 1 deletion google/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
except ImportError:
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
__path__ = pkgutil.extend_path(__path__, __name__) # type: ignore
4 changes: 2 additions & 2 deletions google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import Any, Optional, Union

from dateutil import relativedelta
from google.cloud._helpers import UTC
from google.cloud._helpers import UTC # type: ignore
from google.cloud._helpers import _date_from_iso8601_date
from google.cloud._helpers import _datetime_from_microseconds
from google.cloud._helpers import _RFC3339_MICROS
Expand Down Expand Up @@ -126,7 +126,7 @@ def __init__(self):
def installed_version(self) -> packaging.version.Version:
"""Return the parsed version of pyarrow."""
if self._installed_version is None:
import pyarrow
import pyarrow # type: ignore

self._installed_version = packaging.version.parse(
# Use 0.0.0, since it is earlier than any released version.
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigquery/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os
import pkg_resources

from google.cloud import _http # pytype: disable=import-error
from google.cloud import _http # type: ignore # pytype: disable=import-error
from google.cloud.bigquery import __version__


Expand Down
8 changes: 4 additions & 4 deletions google/cloud/bigquery/_pandas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
import warnings

try:
import pandas
import pandas # type: ignore
except ImportError: # pragma: NO COVER
pandas = None
else:
import numpy

try:
# _BaseGeometry is used to detect shapely objevys in `bq_to_arrow_array`
from shapely.geometry.base import BaseGeometry as _BaseGeometry
from shapely.geometry.base import BaseGeometry as _BaseGeometry # type: ignore
except ImportError: # pragma: NO COVER
# No shapely, use NoneType for _BaseGeometry as a placeholder.
_BaseGeometry = type(None)
Expand All @@ -43,7 +43,7 @@ def _to_wkb():
# - Avoid extra work done by `shapely.wkb.dumps` that we don't need.
# - Caches the WKBWriter (and write method lookup :) )
# - Avoids adding WKBWriter, lgeos, and notnull to the module namespace.
from shapely.geos import WKBWriter, lgeos
from shapely.geos import WKBWriter, lgeos # type: ignore

write = WKBWriter(lgeos).write
notnull = pandas.notnull
Expand Down Expand Up @@ -574,7 +574,7 @@ def dataframe_to_parquet(
"""
pyarrow = _helpers.PYARROW_VERSIONS.try_import(raise_if_error=True)

import pyarrow.parquet
import pyarrow.parquet # type: ignore

kwargs = (
{"use_compliant_nested_type": parquet_use_compliant_nested_type}
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigquery/_tqdm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import warnings

try:
import tqdm
import tqdm # type: ignore
except ImportError: # pragma: NO COVER
tqdm = None

Expand Down
Loading

0 comments on commit 66b3dd9

Please sign in to comment.