diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index d2302469518d..f457c3df7b23 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -187,7 +187,11 @@ Ignoring a whole file --------------------- A ``# type: ignore`` comment at the top of a module (before any statements, -including imports or docstrings) has the effect of ignoring the *entire* module. +including imports or docstrings) has the effect of ignoring the entire contents of the module. + +To only ignore errors, use a top-level ``# mypy: ignore-errors`` comment instead. +To only ignore errors with a specific error code, use a top-level +``# mypy: disable-error-code=...`` comment. .. code-block:: python diff --git a/mypy/fastparse.py b/mypy/fastparse.py index ad7bf2ddf06b..40adb165a746 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -482,6 +482,16 @@ def translate_stmt_list( and self.type_ignores and min(self.type_ignores) < self.get_lineno(stmts[0]) ): + if self.type_ignores[min(self.type_ignores)]: + self.fail( + ( + "type ignore with error code is not supported at module level; " + "use `# mypy: disable-error-code=...`" + ), + line=min(self.type_ignores), + column=0, + blocker=False, + ) self.errors.used_ignored_lines[self.errors.file][min(self.type_ignores)].append( codes.FILE.code )