diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 000000000000..e36c23ebbc8a --- /dev/null +++ b/mypy.ini @@ -0,0 +1,100 @@ +[mypy] +namespace_packages = True +ignore_missing_imports = False + +# Helps mypy navigate the "google" namespace more reliably in 3.10+ +explicit_package_bases = True + +# Performance: reuse results from previous runs to speed up "nox" +incremental = True + +exclude = (?x)( + (^|/)third_party/ + | (^|/)tests/unit/resources/ + | (^|/)tests/unit/gapic/ + ) + + +# ============================================================================== +# GLOBAL THIRD-PARTY & SHARED LIBRARY IGNORES +# ============================================================================== + +[mypy-anywidget] +ignore_missing_imports = True + +[mypy-cloudpickle.*] +ignore_missing_imports = True + +[mypy-flask] +ignore_missing_imports = True + +[mypy-google.auth.*] +ignore_missing_imports = True + +[mypy-google.cloud.bigtable] +ignore_missing_imports = True + +[mypy-google.cloud.pubsub] +ignore_missing_imports = True + +[mypy-google.colab] +ignore_missing_imports = True + +[mypy-google.iam.*] +ignore_missing_imports = True + +[mypy-google.longrunning.*] +ignore_missing_imports = True + +[mypy-google.oauth2.*] +ignore_missing_imports = True + +[mypy-google.protobuf.*] +ignore_missing_imports = True + +[mypy-google.rpc.*] +ignore_missing_imports = True + +[mypy-google.type.*] +ignore_missing_imports = True + +[mypy-grpc.*] +ignore_missing_imports = True + +[mypy-ibis.*] +ignore_missing_imports = True + +[mypy-ipywidgets] +ignore_missing_imports = True + +[mypy-proto.*] +ignore_missing_imports = True + +[mypy-pyarrow.*] +ignore_missing_imports = True + +[mypy-pydata_google_auth] +ignore_missing_imports = True + +[mypy-pytest] +ignore_missing_imports = True + +[mypy-pytz] +ignore_missing_imports = True + + +# ============================================================================== +# PACKAGE-SPECIFIC OVERRIDES & EXCEPTIONS +# ============================================================================== + +# --- google-cloud-bigtable --- +[mypy-google.cloud.bigtable.*] +ignore_errors = True + +[mypy-google.cloud.bigtable.data.*] +check_untyped_defs = True +warn_unreachable = True +disallow_any_generics = True +ignore_errors = False + + diff --git a/packages/gapic-generator/gapic/ads-templates/mypy.ini.j2 b/packages/gapic-generator/gapic/ads-templates/mypy.ini.j2 deleted file mode 100644 index cb397f571128..000000000000 --- a/packages/gapic-generator/gapic/ads-templates/mypy.ini.j2 +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.10 -namespace_packages = True diff --git a/packages/gapic-generator/gapic/ads-templates/noxfile.py.j2 b/packages/gapic-generator/gapic/ads-templates/noxfile.py.j2 index 0a42cd6e4fa0..22baab3fcf23 100644 --- a/packages/gapic-generator/gapic/ads-templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/ads-templates/noxfile.py.j2 @@ -3,9 +3,13 @@ {% block content %} import os +import pathlib import nox # type: ignore +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2450): # Add tests for Python 3.15 alpha1 @@ -44,6 +48,7 @@ def mypy(session): session.install('.') session.run( 'mypy', + f"--config-file={MYPY_CONFIG_FILE}", {% if api.naming.module_namespace %} '{{ api.naming.module_namespace[0] }}', {% else %} diff --git a/packages/gapic-generator/gapic/templates/mypy.ini.j2 b/packages/gapic-generator/gapic/templates/mypy.ini.j2 deleted file mode 100644 index defc5b1ed854..000000000000 --- a/packages/gapic-generator/gapic/templates/mypy.ini.j2 +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True \ No newline at end of file diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index db4a29fcf9db..d79748fa1926 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -40,6 +40,8 @@ DEFAULT_PYTHON_VERSION = "3.14" PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "{{ api.naming.warehouse_package_name }}" @@ -96,6 +98,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", {% if api.naming.module_namespace %} "{{ api.naming.module_namespace[0] }}", diff --git a/packages/gapic-generator/rules_python_gapic/test/integration_test.bzl b/packages/gapic-generator/rules_python_gapic/test/integration_test.bzl index 82e27a7ad5ce..6a1107609c7e 100644 --- a/packages/gapic-generator/rules_python_gapic/test/integration_test.bzl +++ b/packages/gapic-generator/rules_python_gapic/test/integration_test.bzl @@ -114,8 +114,9 @@ def _overwrite_golden_impl(ctx): golden_update_script_content = """ cd ${{BUILD_WORKSPACE_DIRECTORY}} # Filename pattern-based removal is needed to preserve the BUILD.bazel file. - find tests/integration/goldens/{api_name}/ -name \\*.py-type f -delete + find tests/integration/goldens/{api_name}/ -name \\*.py -type f -delete find tests/integration/goldens/{api_name}/ -name \\*.json -type f -delete + find tests/integration/goldens/{api_name}/ -name \\*.ini -type f -delete unzip -ao {goldens_output_zip} -d tests/integration/goldens/{api_name} """.format( goldens_output_zip = goldens_output_zip.path, diff --git a/packages/gapic-generator/tests/integration/goldens/asset/mypy.ini b/packages/gapic-generator/tests/integration/goldens/asset/mypy.ini deleted file mode 100755 index e0e0da2e9e40..000000000000 --- a/packages/gapic-generator/tests/integration/goldens/asset/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 9abef9c30d27..5ef3b438213a 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -47,6 +47,8 @@ PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "google-cloud-asset" @@ -103,6 +105,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", "google", "--check-untyped-defs", diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/mypy.ini b/packages/gapic-generator/tests/integration/goldens/credentials/mypy.ini deleted file mode 100755 index e0e0da2e9e40..000000000000 --- a/packages/gapic-generator/tests/integration/goldens/credentials/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index bfa0326f3845..fb37a81868af 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -47,6 +47,8 @@ PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "google-iam-credentials" @@ -103,6 +105,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", "google", "--check-untyped-defs", diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/mypy.ini b/packages/gapic-generator/tests/integration/goldens/eventarc/mypy.ini deleted file mode 100755 index e0e0da2e9e40..000000000000 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index 18dbb71ca4ee..fd66b3bf70d2 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -47,6 +47,8 @@ PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "google-cloud-eventarc" @@ -103,6 +105,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", "google", "--check-untyped-defs", diff --git a/packages/gapic-generator/tests/integration/goldens/logging/mypy.ini b/packages/gapic-generator/tests/integration/goldens/logging/mypy.ini deleted file mode 100755 index e0e0da2e9e40..000000000000 --- a/packages/gapic-generator/tests/integration/goldens/logging/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index f7e6f9091aaf..17341a3b7c8c 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -47,6 +47,8 @@ PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "google-cloud-logging" @@ -103,6 +105,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", "google", "--check-untyped-defs", diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/mypy.ini b/packages/gapic-generator/tests/integration/goldens/logging_internal/mypy.ini deleted file mode 100755 index e0e0da2e9e40..000000000000 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index f7e6f9091aaf..17341a3b7c8c 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -47,6 +47,8 @@ PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "google-cloud-logging" @@ -103,6 +105,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", "google", "--check-untyped-defs", diff --git a/packages/gapic-generator/tests/integration/goldens/redis/mypy.ini b/packages/gapic-generator/tests/integration/goldens/redis/mypy.ini deleted file mode 100755 index e0e0da2e9e40..000000000000 --- a/packages/gapic-generator/tests/integration/goldens/redis/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index 05e6e98292a4..575ed96f477a 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -47,6 +47,8 @@ PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "google-cloud-redis" @@ -103,6 +105,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", "google", "--check-untyped-defs", diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/mypy.ini b/packages/gapic-generator/tests/integration/goldens/redis_selective/mypy.ini deleted file mode 100755 index e0e0da2e9e40..000000000000 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index 05e6e98292a4..575ed96f477a 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -47,6 +47,8 @@ PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "google-cloud-redis" @@ -103,6 +105,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", "google", "--check-untyped-defs", diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/mypy.ini b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/mypy.ini deleted file mode 100755 index e0e0da2e9e40..000000000000 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -python_version = 3.14 -namespace_packages = True -ignore_missing_imports = False - -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563): -# Dependencies that historically lacks py.typed markers -[mypy-google.iam.*] -ignore_missing_imports = True - -# Helps mypy navigate the 'google' namespace more reliably in 3.10+ -explicit_package_bases = True - -# Performance: reuse results from previous runs to speed up 'nox' -incremental = True diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index 9dbe1aa24718..b1b3990d49fb 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -47,6 +47,8 @@ PREVIEW_PYTHON_VERSION = "3.14" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +# Path to the centralized mypy configuration file at the repository root. +MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini") LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" PACKAGE_NAME = "google-cloud-storagebatchoperations" @@ -103,6 +105,7 @@ def mypy(session): session.install(".") session.run( "mypy", + f"--config-file={MYPY_CONFIG_FILE}", "-p", "google", "--check-untyped-defs",