diff --git a/conformance/results/mypy/directives_type_ignore.toml b/conformance/results/mypy/directives_type_ignore.toml index 8dfefb37..5ac164ed 100644 --- a/conformance/results/mypy/directives_type_ignore.toml +++ b/conformance/results/mypy/directives_type_ignore.toml @@ -5,11 +5,8 @@ Does not honor "# type: ignore" comment if comment includes additional text. output = """ directives_type_ignore.py:11: error: Invalid "type: ignore" comment [syntax] directives_type_ignore.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] -directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] -directives_type_ignore.py:14: note: Error code "assignment" not covered by "type: ignore" comment """ conformance_automated = "Fail" errors_diff = """ Line 11: Unexpected errors ['directives_type_ignore.py:11: error: Invalid "type: ignore" comment [syntax]', 'directives_type_ignore.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]'] -Line 14: Unexpected errors ['directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]'] """ diff --git a/conformance/results/results.html b/conformance/results/results.html index 95f5422b..1528d66e 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1191,7 +1191,7 @@

Python Type System Conformance Test Results

     directives_type_ignore
Partial

Does not honor "# type: ignore" comment if comment includes additional text.

Pass -
Partial

Does not honor "# type: ignore" comment if comment includes additional text.

+Pass Pass
Partial

Treats `# type: ignore[error-code]` as only ignoring errors that match the error code `error-code`.

diff --git a/conformance/results/zuban/directives_type_ignore.toml b/conformance/results/zuban/directives_type_ignore.toml index 2e7de839..cdd4d0cd 100644 --- a/conformance/results/zuban/directives_type_ignore.toml +++ b/conformance/results/zuban/directives_type_ignore.toml @@ -1,12 +1,5 @@ -conformant = "Partial" -notes = """ -Does not honor "# type: ignore" comment if comment includes additional text. -""" -conformance_automated = "Fail" +conformance_automated = "Pass" errors_diff = """ -Line 14: Unexpected errors ['directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]'] """ output = """ -directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] -directives_type_ignore.py:14: note: Error code "assignment" not covered by "type: ignore" comment """ diff --git a/conformance/tests/directives_type_ignore.py b/conformance/tests/directives_type_ignore.py index b96d23ae..ef44c353 100644 --- a/conformance/tests/directives_type_ignore.py +++ b/conformance/tests/directives_type_ignore.py @@ -10,8 +10,10 @@ # The following type violation should be suppressed. y: int = "" # type: ignore - additional stuff -# The following type violation should be suppressed. -z: int = "" # type: ignore[additional_stuff] +# The following type violation may be suppressed, depending whether the +# type checker uses the error code `assignment` for invalid assignments, +# and/or how it treats unknown error codes. +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 6ed7016a..5a7d5e7c 100644 --- a/docs/spec/directives.rst +++ b/docs/spec/directives.rst @@ -73,6 +73,15 @@ other comments and linting markers: # type: ignore # +The form ``# type: ignore[...]`` may be used to suppress only type errors with a +given error code, though support for this is optional and may vary by type checker: + +- Given ``# type: ignore[my_code1]``, a type checker may ignore the error code + ``my_code1`` and choose to treat this form as equivalent to ``# type: ignore``. +- Alternatively, given ``# type: ignore[my_code1]`` a type checker may suppress the + error only if the error cause matches the error code ``my_code1``. +- A bare ``# type: ignore`` must always suppress all type errors. + .. _`cast`: ``cast()``