diff --git a/contributing-docs/08_static_code_checks.rst b/contributing-docs/08_static_code_checks.rst index ab4ec43edec23..b8144881544f2 100644 --- a/contributing-docs/08_static_code_checks.rst +++ b/contributing-docs/08_static_code_checks.rst @@ -508,6 +508,12 @@ For example: pre-commit run --hook-stage manual mypy-airflow --all-files +To show unused mypy ignores for any providers/airflow etc, eg: run below command: + +.. code-block:: bash + export SHOW_UNUSED_MYPY_WARNINGS=true + pre-commit run --hook-stage manual mypy-airflow --all-files + MyPy uses a separate docker-volume (called ``mypy-cache-volume``) that keeps the cache of last MyPy execution in order to speed MyPy checks up (sometimes by order of magnitude). While in most cases MyPy will handle refreshing the cache when and if needed, there are some cases when it won't (cache invalidation diff --git a/scripts/ci/pre_commit/mypy_folder.py b/scripts/ci/pre_commit/mypy_folder.py index d3ca454e38524..87704282fc41c 100755 --- a/scripts/ci/pre_commit/mypy_folder.py +++ b/scripts/ci/pre_commit/mypy_folder.py @@ -53,6 +53,8 @@ mypy_folders = sys.argv[1:] +show_unused_warnings = os.environ.get("SHOW_UNUSED_MYPY_WARNINGS", "false") + for mypy_folder in mypy_folders: if mypy_folder not in ALLOWED_FOLDERS: console.print( @@ -125,6 +127,15 @@ def get_all_files(folder: str) -> list[str]: print(f"Running mypy with {FILE_ARGUMENT}") +if show_unused_warnings == "true": + console.print( + "[info]Running mypy with --warn-unused-ignores to display unused ignores, unset environment variable: SHOW_UNUSED_MYPY_WARNINGS to runoff this behaviour" + ) + + mypy_cmd = f"TERM=ansi mypy {shlex.quote(FILE_ARGUMENT)} --warn-unused-ignores" +else: + mypy_cmd = f"TERM=ansi mypy {shlex.quote(FILE_ARGUMENT)}" + cmd = ["bash", "-c", f"TERM=ansi mypy {shlex.quote(FILE_ARGUMENT)}"] res = run_command_via_breeze_shell(