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' files #149

Merged
merged 9 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/_helpers/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# This package uses inline types.
File renamed without changes.
2 changes: 2 additions & 0 deletions google/cloud/_http/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# This package uses inline types.
File renamed without changes.
2 changes: 2 additions & 0 deletions google/cloud/_testing/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# This package uses inline types.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/client/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# This package uses inline types.
2 changes: 2 additions & 0 deletions google/cloud/environment_vars/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# This package uses inline types.
File renamed without changes.
2 changes: 2 additions & 0 deletions google/cloud/exceptions/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# This package uses inline types.
File renamed without changes.
2 changes: 2 additions & 0 deletions google/cloud/obsolete/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# This package uses inline types.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/operation/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# This 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
10 changes: 10 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down