Skip to content

Commit 0023ee1

Browse files
authored
fix: add mypy checking + 'py.typed' file (#290)
1 parent e6a3489 commit 0023ee1

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

google/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
except ImportError:
2222
import pkgutil
2323

24-
__path__ = pkgutil.extend_path(__path__, __name__)
24+
__path__ = pkgutil.extend_path(__path__, __name__) # type: ignore

google/api_core/client_info.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"""
2020

2121
import platform
22+
from typing import Union
2223

2324
import pkg_resources
2425

@@ -27,6 +28,8 @@
2728
_PY_VERSION = platform.python_version()
2829
_API_CORE_VERSION = api_core_version.__version__
2930

31+
_GRPC_VERSION: Union[str, None]
32+
3033
try:
3134
_GRPC_VERSION = pkg_resources.get_distribution("grpcio").version
3235
except pkg_resources.DistributionNotFound: # pragma: NO COVER

google/api_core/exceptions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
from __future__ import unicode_literals
2323

2424
import http.client
25+
from typing import Dict
26+
from typing import Union
2527

2628
try:
2729
import grpc
28-
2930
except ImportError: # pragma: NO COVER
3031
grpc = None
3132

3233
# Lookup tables for mapping exceptions from HTTP and gRPC transports.
3334
# Populated by _GoogleAPICallErrorMeta
34-
_HTTP_CODE_TO_EXCEPTION = {}
35-
_GRPC_CODE_TO_EXCEPTION = {}
35+
_HTTP_CODE_TO_EXCEPTION: Dict[int, Exception] = {}
36+
_GRPC_CODE_TO_EXCEPTION: Dict[int, Exception] = {}
3637

3738
# Additional lookup table to map integer status codes to grpc status code
3839
# grpc does not currently support initializing enums from ints
@@ -100,7 +101,7 @@ class GoogleAPICallError(GoogleAPIError, metaclass=_GoogleAPICallErrorMeta):
100101
gRPC call metadata.
101102
"""
102103

103-
code = None
104+
code: Union[int, None] = None
104105
"""Optional[int]: The HTTP status code associated with this error.
105106
106107
This may be ``None`` if the exception does not have a direct mapping

google/api_core/py.typed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# The google-api-core package uses inline types.

mypy.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[mypy]
2+
python_version = 3.6
3+
namespace_packages = True
4+
ignore_missing_imports = True
5+
6+
[mypy-google.protobuf]
7+
ignore_missing_imports = True

noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"unit_grpc_gcp",
3636
"cover",
3737
"pytype",
38+
"mypy",
3839
"lint",
3940
"lint_setup_py",
4041
"blacken",
@@ -155,6 +156,14 @@ def pytype(session):
155156
session.run("pytype")
156157

157158

159+
@nox.session(python=DEFAULT_PYTHON_VERSION)
160+
def mypy(session):
161+
"""Run type-checking."""
162+
session.install(".[grpc, grpcgcp]", "mypy")
163+
session.install("types-setuptools", "types-requests", "types-mock")
164+
session.run("mypy", "google", "tests")
165+
166+
158167
@nox.session(python="3.6")
159168
def cover(session):
160169
"""Run the final coverage report.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy