diff options
author | Tres Seaver <tseaver@palladion.com> | 2021-10-13 17:54:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 17:54:33 -0400 |
commit | 0023ee1fe0e8b80c7a9e8987e0f322a829e5d613 (patch) | |
tree | 9b217b24b0d19adc3f4049707135cf4c56194fb5 | |
parent | e6a3489a79da00a5de919a4a41782cc3b1d7f583 (diff) | |
download | python-api-core-0023ee1fe0e8b80c7a9e8987e0f322a829e5d613.tar.gz |
fix: add mypy checking + 'py.typed' file (#290)
-rw-r--r-- | google/__init__.py | 2 | ||||
-rw-r--r-- | google/api_core/client_info.py | 3 | ||||
-rw-r--r-- | google/api_core/exceptions.py | 9 | ||||
-rw-r--r-- | google/api_core/py.typed | 2 | ||||
-rw-r--r-- | mypy.ini | 7 | ||||
-rw-r--r-- | noxfile.py | 9 |
6 files changed, 27 insertions, 5 deletions
diff --git a/google/__init__.py b/google/__init__.py index 0d0a4c3..70a7bd9 100644 --- a/google/__init__.py +++ b/google/__init__.py @@ -21,4 +21,4 @@ try: except ImportError: import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) + __path__ = pkgutil.extend_path(__path__, __name__) # type: ignore diff --git a/google/api_core/client_info.py b/google/api_core/client_info.py index d7f4367..e093ffd 100644 --- a/google/api_core/client_info.py +++ b/google/api_core/client_info.py @@ -19,6 +19,7 @@ such as the library and Python version, to API services. """ import platform +from typing import Union import pkg_resources @@ -27,6 +28,8 @@ from google.api_core import version as api_core_version _PY_VERSION = platform.python_version() _API_CORE_VERSION = api_core_version.__version__ +_GRPC_VERSION: Union[str, None] + try: _GRPC_VERSION = pkg_resources.get_distribution("grpcio").version except pkg_resources.DistributionNotFound: # pragma: NO COVER diff --git a/google/api_core/exceptions.py b/google/api_core/exceptions.py index b0909f1..2cfc2e4 100644 --- a/google/api_core/exceptions.py +++ b/google/api_core/exceptions.py @@ -22,17 +22,18 @@ from __future__ import absolute_import from __future__ import unicode_literals import http.client +from typing import Dict +from typing import Union try: import grpc - except ImportError: # pragma: NO COVER grpc = None # Lookup tables for mapping exceptions from HTTP and gRPC transports. # Populated by _GoogleAPICallErrorMeta -_HTTP_CODE_TO_EXCEPTION = {} -_GRPC_CODE_TO_EXCEPTION = {} +_HTTP_CODE_TO_EXCEPTION: Dict[int, Exception] = {} +_GRPC_CODE_TO_EXCEPTION: Dict[int, Exception] = {} # Additional lookup table to map integer status codes to grpc status code # grpc does not currently support initializing enums from ints @@ -100,7 +101,7 @@ class GoogleAPICallError(GoogleAPIError, metaclass=_GoogleAPICallErrorMeta): gRPC call metadata. """ - code = None + code: Union[int, None] = None """Optional[int]: The HTTP status code associated with this error. This may be ``None`` if the exception does not have a direct mapping diff --git a/google/api_core/py.typed b/google/api_core/py.typed new file mode 100644 index 0000000..1d5517b --- /dev/null +++ b/google/api_core/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561.
+# The google-api-core package uses inline types.
diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..5663b40 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,7 @@ +[mypy] +python_version = 3.6 +namespace_packages = True +ignore_missing_imports = True + +[mypy-google.protobuf] +ignore_missing_imports = True @@ -35,6 +35,7 @@ nox.options.sessions = [ "unit_grpc_gcp", "cover", "pytype", + "mypy", "lint", "lint_setup_py", "blacken", @@ -155,6 +156,14 @@ def pytype(session): session.run("pytype") +@nox.session(python=DEFAULT_PYTHON_VERSION) +def mypy(session): + """Run type-checking.""" + session.install(".[grpc, grpcgcp]", "mypy") + session.install("types-setuptools", "types-requests", "types-mock") + session.run("mypy", "google", "tests") + + @nox.session(python="3.6") def cover(session): """Run the final coverage report. |