Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f20ef60

Browse filesBrowse files
authored
fix: add mypy checking + 'py.typed' files (#149)
* ci: add mypy checking * chore: add py.typed file. * chore: use DEFAULT_PYTHON_VERSION to run mypy * fix: add typing for 'Client.SCOPE' * fix: cannot have 'py.typed' in the namespace package dir * chore: make top-level modules in 'google/core' into packages FBO typing, which interprets 'py.typed' file as always-inherited in subdirs. * chore: back out converson of 'version.py' to a package Our 'release-please' tooling won't find it there, and nobody is likely to a) import the module, and then b) choke on its lack of typing. * chore: fix thinko
1 parent 35d78d0 commit f20ef60
Copy full SHA for f20ef60

File tree

Expand file treeCollapse file tree

21 files changed

+45
-6
lines changed
Filter options
Expand file treeCollapse file tree

21 files changed

+45
-6
lines changed

‎.coveragerc

Copy file name to clipboardExpand all lines: .coveragerc
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ branch = True
33

44
[report]
55
omit =
6-
google/cloud/_testing.py
76
google/cloud/__init__.py
8-
google/cloud/environment_vars.py
7+
google/cloud/_testing/__init__.py
8+
google/cloud/environment_vars/__init__.py
99
fail_under = 100
1010
show_missing = True
1111
exclude_lines =

‎google/__init__.py

Copy file name to clipboardExpand all lines: google/__init__.py
+1-1Lines 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/cloud/__init__.py

Copy file name to clipboardExpand all lines: google/cloud/__init__.py
+1-1Lines 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/cloud/_helpers.py renamed to ‎google/cloud/_helpers/__init__.py

Copy file name to clipboardExpand all lines: google/cloud/_helpers/__init__.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import re
2727
from threading import local as Local
28+
from typing import Union
2829

2930
import google.auth
3031
import google.auth.transport.requests
@@ -62,6 +63,7 @@
6263
)
6364
# NOTE: Catching this ImportError is a workaround for GAE not supporting the
6465
# "pwd" module which is imported lazily when "expanduser" is called.
66+
_USER_ROOT: Union[str, None]
6567
try:
6668
_USER_ROOT = os.path.expanduser("~")
6769
except ImportError: # pragma: NO COVER

‎google/cloud/_helpers/py.typed

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# This package uses inline types.
File renamed without changes.

‎google/cloud/_http/py.typed

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# This package uses inline types.
File renamed without changes.

‎google/cloud/_testing/py.typed

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# This package uses inline types.

‎google/cloud/client.py renamed to ‎google/cloud/client/__init__.py

Copy file name to clipboardExpand all lines: google/cloud/client/__init__.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import json
1919
import os
2020
from pickle import PicklingError
21+
from typing import Tuple
22+
from typing import Union
2123

2224
import google.api_core.client_options
2325
import google.api_core.exceptions
@@ -142,7 +144,7 @@ class Client(_ClientFactoryMixin):
142144
to acquire default credentials.
143145
"""
144146

145-
SCOPE = None
147+
SCOPE: Union[Tuple[str], None] = None
146148
"""The scopes required for authenticating with a service.
147149
148150
Needs to be set by subclasses.

‎google/cloud/client/py.typed

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# This package uses inline types.
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# This package uses inline types.
File renamed without changes.

‎google/cloud/exceptions/py.typed

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# This package uses inline types.
File renamed without changes.

‎google/cloud/obsolete/py.typed

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# This package uses inline types.

‎google/cloud/operation.py renamed to ‎google/cloud/operation/__init__.py

Copy file name to clipboardExpand all lines: google/cloud/operation/__init__.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
"""Wrap long-running operations returned from Google Cloud APIs."""
1616

17+
from typing import Dict
18+
1719
from google.longrunning import operations_pb2
1820
from google.protobuf import json_format
1921

2022

2123
_GOOGLE_APIS_PREFIX = "type.googleapis.com"
2224

23-
_TYPE_URL_MAP = {}
25+
_TYPE_URL_MAP: Dict[str, type] = {}
2426

2527

2628
def _compute_type_url(klass, prefix=_GOOGLE_APIS_PREFIX):

‎google/cloud/operation/py.typed

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# This package uses inline types.

‎mypy.ini

Copy file name to clipboard
+7Lines 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

Copy file name to clipboardExpand all lines: noxfile.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def lint(session):
3838
session.run("flake8", "google", "tests")
3939

4040

41+
@nox.session(python=DEFAULT_PYTHON_VERSION)
42+
def mypy(session):
43+
"""Run type-checking."""
44+
session.install(".", "mypy")
45+
session.install(
46+
"types-setuptools", "types-requests", "types-mock", "types-protobuf",
47+
)
48+
session.run("mypy", "google", "tests")
49+
50+
4151
@nox.session(python=DEFAULT_PYTHON_VERSION)
4252
def blacken(session):
4353
"""Run black.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.