From f4a919aff6c296e3d084dfc4e00394c7f11415fd Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 25 Feb 2026 22:05:55 +0100 Subject: [PATCH] Allow type: ignore error codes filtering --- conformance/tests/directives_type_ignore.py | 2 +- docs/spec/directives.rst | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/conformance/tests/directives_type_ignore.py b/conformance/tests/directives_type_ignore.py index b96d23aea..f76802b94 100644 --- a/conformance/tests/directives_type_ignore.py +++ b/conformance/tests/directives_type_ignore.py @@ -11,7 +11,7 @@ y: int = "" # type: ignore - additional stuff # The following type violation should be suppressed. -z: int = "" # type: ignore[additional_stuff] +z: int = "" # type: ignore[assignment] # > In some cases, linting tools or other comments may be needed on the same # > line as a type comment. In these cases, the type comment should be before diff --git a/docs/spec/directives.rst b/docs/spec/directives.rst index 6ed7016a7..927c4081c 100644 --- a/docs/spec/directives.rst +++ b/docs/spec/directives.rst @@ -73,6 +73,13 @@ other comments and linting markers: # type: ignore # +Any text following ``# type: ignore`` is ignored, provided there is at least one +whitespace character after ``# type: ignore``. The form of +``# type: ignore[error_code1, error_code2]`` can be used to filter error codes +that may vary across type checkers. Type checkers may ignore the bracketed +codes and treat this form as equivalent to ``# type: ignore``. + + .. _`cast`: ``cast()``