398398s .replace (
399399 "noxfile.py" ,
400400 r"BLACK_PATHS = \[.*?\]" ,
401- '\g<0>\n \ n PYTYPE_VERSION = "pytype==2021.4.9"\n ' ,
401+ '\g<0>\n PYTYPE_VERSION = "pytype==2021.4.9"\n ' ,
402402)
403403s .replace (
404404 "noxfile.py" , r'"blacken",' , '\g<0>\n "pytype",' ,
@@ -418,8 +418,46 @@ def pytype(session):
418418 session.run("pytype")'''
419419 ),
420420)
421+
422+ # ----------------------------------------------------------------------------
423+ # Add mypy nox session.
424+ # ----------------------------------------------------------------------------
425+ s .replace (
426+ "noxfile.py" ,
427+ r"BLACK_PATHS = \[.*?\]" ,
428+ '\g<0>\n \n MYPY_VERSION = "mypy==0.910"' ,
429+ )
430+ s .replace (
431+ "noxfile.py" , r'"blacken",' , '\g<0>\n "mypy",' ,
432+ )
433+ s .replace (
434+ "noxfile.py" ,
435+ r"nox\.options\.error_on_missing_interpreters = True" ,
436+ textwrap .dedent (
437+ ''' \g<0>
438+
439+
440+ @nox.session(python=DEFAULT_PYTHON_VERSION)
441+ def mypy(session):
442+ """Run type checks with mypy."""
443+ session.install("-e", ".[all]")
444+ session.install(MYPY_VERSION)
445+
446+ # Just install the type info directly, since "mypy --install-types" might
447+ # require an additional pass.
448+ session.install("types-protobuf", "types-setuptools")
449+
450+ # TODO: Only check the hand-written layer, the generated code does not pass
451+ # mypy checks yet.
452+ # https://github.com/googleapis/gapic-generator-python/issues/1092
453+ session.run("mypy", "google/cloud")'''
454+ ),
455+ )
456+
457+ # Only consider the hand-written layer when assessing the test coverage.
421458s .replace (
422459 "noxfile.py" , "--cov=google" , "--cov=google/cloud" ,
423460)
424461
462+ # Final code style adjustments.
425463s .shell .run (["nox" , "-s" , "blacken" ], hide_output = False )
0 commit comments