Skip to content

Commit 74ec755

Browse files
committed
build: update to the latest version of mypy
1 parent e082ba7 commit 74ec755

File tree

12 files changed

+30
-27
lines changed

12 files changed

+30
-27
lines changed

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
python_version = 3.6
2+
python_version = 3.8
33
ignore_missing_imports = True
44

55

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def blacken(session):
3333

3434
@nox.session(python=PYTHON_VERSIONS)
3535
def lint(session):
36-
session.install('mypy==0.790', 'flake8', 'black==23.3.0')
36+
session.install('mypy', 'flake8', 'black==23.3.0', 'types-protobuf', 'types-PyYAML', 'types-requests')
3737
session.run('pip', 'install', '-e', '.')
3838
session.run('pip', 'install', 'click>8.0')
3939
session.run('black', '--check', 'synthtool', 'tests')

synthtool/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# Make sure that synthtool is being used instead of running the synth file
4040
# directly
4141
_main_module = sys.modules["__main__"]
42-
if hasattr(_main_module, "__file__") and "synthtool" not in _main_module.__file__:
42+
if hasattr(_main_module, "__file__") and "synthtool" not in str(_main_module.__file__):
4343
logger.critical(
4444
"You are running the synthesis script directly, this will be disabled in a future release of Synthtool. Please use python3 -m synthtool instead."
4545
)

synthtool/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ def main(synthfile: str, metadata: str, extra_args: Sequence[str]):
8585
logger.debug(f"Executing {synth_file}.")
8686
# https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
8787
spec = importlib.util.spec_from_file_location("synth", synth_file)
88-
synth_module = importlib.util.module_from_spec(spec)
8988

90-
if spec.loader is None:
89+
if not spec or spec.loader is None:
9190
raise ImportError("Could not import synth.py")
9291

92+
synth_module = importlib.util.module_from_spec(spec)
93+
9394
with synthtool.metadata.MetadataTrackerAndWriter(metadata):
9495
spec.loader.exec_module(synth_module) # type: ignore
9596

synthtool/gcp/gapic_bazel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ def _generate_code(
8080
private: bool = False,
8181
discogapic: bool = False,
8282
diregapic: bool = False,
83-
proto_path: Union[str, Path] = None,
84-
output_dir: Union[str, Path] = None,
85-
bazel_target: str = None,
83+
proto_path: Optional[Union[str, Path]] = None,
84+
output_dir: Optional[Union[str, Path]] = None,
85+
bazel_target: Optional[str] = None,
8686
include_protos: bool = False,
87-
proto_output_path: Union[str, Path] = None,
87+
proto_output_path: Optional[Union[str, Path]] = None,
8888
tar_strip_components: int = 1,
8989
):
9090
# Determine which googleapis repo to use

synthtool/gcp/gapic_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ def _include_samples(
237237
version: str,
238238
genfiles: Path,
239239
googleapis_service_dir: Path,
240-
samples_root_dir: Path = None,
241-
samples_resources_dir: Path = None,
240+
samples_root_dir: Optional[Path] = None,
241+
samples_resources_dir: Optional[Path] = None,
242242
):
243243
"""Include code samples and supporting resources in generated output.
244244

synthtool/gcp/gapic_microgenerator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ def _generate_code(
7575
language: str,
7676
*,
7777
private: bool = False,
78-
proto_path: Union[str, Path] = None,
78+
proto_path: Optional[Union[str, Path]] = None,
7979
extra_proto_files: List[str] = [],
80-
output_dir: Union[str, Path] = None,
80+
output_dir: Optional[Union[str, Path]] = None,
8181
generator_version: str = GENERATOR_VERSION,
82-
generator_args: Mapping[str, str] = None,
82+
generator_args: Optional[Mapping[str, str]] = None,
8383
):
8484
# Determine which googleapis repo to use
8585
if not private:

synthtool/languages/php.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def owlbot_copy_version(
8383
src: Path,
8484
dest: Path,
8585
copy_excludes: typing.Optional[typing.List[str]] = None,
86-
version_string: str = None,
86+
version_string: typing.Optional[str] = None,
8787
) -> None:
8888
"""Copies files from a version subdirectory."""
8989
logger.debug("owlbot_copy_version called from %s to %s", src, dest)

synthtool/languages/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import json
1919
from pathlib import Path
2020
import shutil
21-
from typing import Any, Dict, List
21+
from typing import Any, Dict, List, Optional
2222
import yaml
2323

2424
import synthtool as s
@@ -108,7 +108,7 @@ def python_notebooks_testing_pipeline() -> None:
108108

109109
def py_samples(
110110
*,
111-
root: PathOrStr = None,
111+
root: Optional[PathOrStr] = None,
112112
skip_readmes: bool = False,
113113
files_to_exclude: List[str] = [],
114114
) -> None:

synthtool/py_templating_instructions/synth-template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
common = gcp.CommonTemplates()
2424
sample_files = common.py_samples()
2525
for path in sample_files:
26-
s.move(path, excludes=["noxfile.py"])
26+
s.move([path], excludes=["noxfile.py"])

synthtool/sources/git.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def _local_default_branch(path: pathlib.Path) -> Union[str, None]:
7373

7474
def clone(
7575
url: str,
76-
dest: pathlib.Path = None,
77-
committish: str = None,
76+
dest: Optional[pathlib.Path] = None,
77+
committish: Optional[str] = None,
7878
force: bool = False,
7979
) -> pathlib.Path:
8080
"""Clones a remote git repo.
@@ -164,7 +164,7 @@ def parse_repo_url(url: str) -> Dict[str, str]:
164164
return {"owner": owner, "name": name}
165165

166166

167-
def get_latest_commit(repo: pathlib.Path = None) -> Tuple[str, str]:
167+
def get_latest_commit(repo: Optional[pathlib.Path] = None) -> Tuple[str, str]:
168168
"""Return the sha and commit message of the latest commit."""
169169
output = subprocess.check_output(
170170
["git", "log", "-1", "--pretty=%H%n%B"], cwd=repo

synthtool/transforms.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class MissingSourceError(Exception):
3131
pass
3232

3333

34-
def _expand_paths(paths: ListOfPathsOrStrs, root: PathOrStr = None) -> Iterable[Path]:
34+
def _expand_paths(
35+
paths: ListOfPathsOrStrs, root: Optional[PathOrStr] = None
36+
) -> Iterable[Path]:
3537
"""Given a list of globs/paths, expands them into a flat sequence,
3638
expanding globs as necessary."""
3739
if paths is None:
@@ -103,8 +105,8 @@ def _merge_file(
103105
def _copy_dir_to_existing_dir(
104106
source: Path,
105107
destination: Path,
106-
excludes: ListOfPathsOrStrs = None,
107-
merge: Callable[[str, str, Path], str] = None,
108+
excludes: Optional[ListOfPathsOrStrs] = None,
109+
merge: Optional[Callable[[str, str, Path], str]] = None,
108110
) -> bool:
109111
"""
110112
copies files over existing files to an existing directory
@@ -169,9 +171,9 @@ def merge(source_text: str, destinaton_text: str, file_path: Path) -> str:
169171

170172
def move(
171173
sources: ListOfPathsOrStrs,
172-
destination: PathOrStr = None,
173-
excludes: ListOfPathsOrStrs = None,
174-
merge: Callable[[str, str, Path], str] = None,
174+
destination: Optional[PathOrStr] = None,
175+
excludes: Optional[ListOfPathsOrStrs] = None,
176+
merge: Optional[Callable[[str, str, Path], str]] = None,
175177
required: bool = False,
176178
) -> bool:
177179
"""

0 commit comments

Comments
 (0)