diff --git a/.coveragerc b/.coveragerc index ce75f60..c6430d3 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,9 +3,9 @@ branch = True [report] omit = - google/cloud/_testing.py google/cloud/__init__.py - google/cloud/environment_vars.py + google/cloud/_testing/__init__.py + google/cloud/environment_vars/__init__.py fail_under = 100 show_missing = True exclude_lines = 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 @@ except ImportError: import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) + __path__ = pkgutil.extend_path(__path__, __name__) # type: ignore diff --git a/google/cloud/__init__.py b/google/cloud/__init__.py index f281ec0..ef78099 100644 --- a/google/cloud/__init__.py +++ b/google/cloud/__init__.py @@ -21,4 +21,4 @@ except ImportError: import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) + __path__ = pkgutil.extend_path(__path__, __name__) # type: ignore diff --git a/google/cloud/_helpers.py b/google/cloud/_helpers/__init__.py similarity index 99% rename from google/cloud/_helpers.py rename to google/cloud/_helpers/__init__.py index d8f2851..291f587 100644 --- a/google/cloud/_helpers.py +++ b/google/cloud/_helpers/__init__.py @@ -25,6 +25,7 @@ import os import re from threading import local as Local +from typing import Union import google.auth import google.auth.transport.requests @@ -62,6 +63,7 @@ ) # NOTE: Catching this ImportError is a workaround for GAE not supporting the # "pwd" module which is imported lazily when "expanduser" is called. +_USER_ROOT: Union[str, None] try: _USER_ROOT = os.path.expanduser("~") except ImportError: # pragma: NO COVER diff --git a/google/cloud/_helpers/py.typed b/google/cloud/_helpers/py.typed new file mode 100644 index 0000000..dfc5374 --- /dev/null +++ b/google/cloud/_helpers/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# This package uses inline types. diff --git a/google/cloud/_http.py b/google/cloud/_http/__init__.py similarity index 100% rename from google/cloud/_http.py rename to google/cloud/_http/__init__.py diff --git a/google/cloud/_http/py.typed b/google/cloud/_http/py.typed new file mode 100644 index 0000000..dfc5374 --- /dev/null +++ b/google/cloud/_http/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# This package uses inline types. diff --git a/google/cloud/_testing.py b/google/cloud/_testing/__init__.py similarity index 100% rename from google/cloud/_testing.py rename to google/cloud/_testing/__init__.py diff --git a/google/cloud/_testing/py.typed b/google/cloud/_testing/py.typed new file mode 100644 index 0000000..dfc5374 --- /dev/null +++ b/google/cloud/_testing/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# This package uses inline types. diff --git a/google/cloud/client.py b/google/cloud/client/__init__.py similarity index 99% rename from google/cloud/client.py rename to google/cloud/client/__init__.py index e058c2d..b3ca4b8 100644 --- a/google/cloud/client.py +++ b/google/cloud/client/__init__.py @@ -18,6 +18,8 @@ import json import os from pickle import PicklingError +from typing import Tuple +from typing import Union import google.api_core.client_options import google.api_core.exceptions @@ -142,7 +144,7 @@ class Client(_ClientFactoryMixin): to acquire default credentials. """ - SCOPE = None + SCOPE: Union[Tuple[str], None] = None """The scopes required for authenticating with a service. Needs to be set by subclasses. diff --git a/google/cloud/client/py.typed b/google/cloud/client/py.typed new file mode 100644 index 0000000..dfc5374 --- /dev/null +++ b/google/cloud/client/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# This package uses inline types. diff --git a/google/cloud/environment_vars.py b/google/cloud/environment_vars/__init__.py similarity index 100% rename from google/cloud/environment_vars.py rename to google/cloud/environment_vars/__init__.py diff --git a/google/cloud/environment_vars/py.typed b/google/cloud/environment_vars/py.typed new file mode 100644 index 0000000..dfc5374 --- /dev/null +++ b/google/cloud/environment_vars/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# This package uses inline types. diff --git a/google/cloud/exceptions.py b/google/cloud/exceptions/__init__.py similarity index 100% rename from google/cloud/exceptions.py rename to google/cloud/exceptions/__init__.py diff --git a/google/cloud/exceptions/py.typed b/google/cloud/exceptions/py.typed new file mode 100644 index 0000000..dfc5374 --- /dev/null +++ b/google/cloud/exceptions/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# This package uses inline types. diff --git a/google/cloud/obsolete.py b/google/cloud/obsolete/__init__.py similarity index 100% rename from google/cloud/obsolete.py rename to google/cloud/obsolete/__init__.py diff --git a/google/cloud/obsolete/py.typed b/google/cloud/obsolete/py.typed new file mode 100644 index 0000000..dfc5374 --- /dev/null +++ b/google/cloud/obsolete/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# This package uses inline types. diff --git a/google/cloud/operation.py b/google/cloud/operation/__init__.py similarity index 99% rename from google/cloud/operation.py rename to google/cloud/operation/__init__.py index 28ac8cf..4fd1f27 100644 --- a/google/cloud/operation.py +++ b/google/cloud/operation/__init__.py @@ -14,13 +14,15 @@ """Wrap long-running operations returned from Google Cloud APIs.""" +from typing import Dict + from google.longrunning import operations_pb2 from google.protobuf import json_format _GOOGLE_APIS_PREFIX = "type.googleapis.com" -_TYPE_URL_MAP = {} +_TYPE_URL_MAP: Dict[str, type] = {} def _compute_type_url(klass, prefix=_GOOGLE_APIS_PREFIX): diff --git a/google/cloud/operation/py.typed b/google/cloud/operation/py.typed new file mode 100644 index 0000000..dfc5374 --- /dev/null +++ b/google/cloud/operation/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# This 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 diff --git a/noxfile.py b/noxfile.py index c29d0f3..8fc781f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -38,6 +38,16 @@ def lint(session): session.run("flake8", "google", "tests") +@nox.session(python=DEFAULT_PYTHON_VERSION) +def mypy(session): + """Run type-checking.""" + session.install(".", "mypy") + session.install( + "types-setuptools", "types-requests", "types-mock", "types-protobuf", + ) + session.run("mypy", "google", "tests") + + @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """Run black.