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

fix: add mypy checking + 'py.typed' file #290

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/__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
3 changes: 3 additions & 0 deletions google/api_core/client_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""

import platform
from typing import Union

import pkg_resources

Expand All @@ -27,6 +28,8 @@
_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
Expand Down
8 changes: 5 additions & 3 deletions google/api_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

from __future__ import absolute_import
from __future__ import unicode_literals
from typing import Union
from typing import Dict

import http.client

Expand All @@ -31,8 +33,8 @@

# 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
Expand Down Expand Up @@ -100,7 +102,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
Expand Down
2 changes: 2 additions & 0 deletions google/api_core/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# The google-api-core package uses inline types.
7 changes: 7 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[mypy]
python_version = 3.6
namespace_packages = True
ignore_missing_imports = True

[mypy-google.protobuf]
ignore_missing_imports = True
9 changes: 9 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"unit_grpc_gcp",
"cover",
"pytype",
"mypy",
"lint",
"lint_setup_py",
"blacken",
Expand Down Expand Up @@ -155,6 +156,14 @@ def pytype(session):
session.run("pytype")


@nox.session(python="3.6")
tseaver marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down