-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(mypy): centralize mypy.ini and update templates #17523
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
||
|
|
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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") | ||
|
Comment on lines
+43
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hardcoded relative path To make this robust across all directory structures (including local development and integration tests), search upwards through parent directories to dynamically locate the References
|
||
|
|
||
| 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] }}", | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded relative path
CURRENT_DIRECTORY.parent.parent / 'mypy.ini'assumes that the generated package is always located exactly two levels down from the repository root. While this is true for standard packages in the monorepo, it is not true for integration test goldens (which are located five levels down atpackages/gapic-generator/tests/integration/goldens/<package>). As a result, runningnox -s mypyinside the golden directories will fail to find the centralizedmypy.inifile.To make this robust across all directory structures (including local development and integration tests), search upwards through parent directories to dynamically locate the
mypy.inifile, falling back to the default relative path if not found.References