diff --git a/conformance/results/mypy/directives_type_ignore.toml b/conformance/results/mypy/directives_type_ignore.toml index 8dfefb37..70ab31d7 100644 --- a/conformance/results/mypy/directives_type_ignore.toml +++ b/conformance/results/mypy/directives_type_ignore.toml @@ -5,11 +5,10 @@ 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 +directives_type_ignore.py:16: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] +directives_type_ignore.py:16: 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..06ac10a9 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1191,9 +1191,9 @@

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 -
Partial

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

+Pass +Pass      directives_type_ignore_file1 Pass diff --git a/conformance/results/ty/directives_type_ignore.toml b/conformance/results/ty/directives_type_ignore.toml index df3a5011..d4a44dd6 100644 --- a/conformance/results/ty/directives_type_ignore.toml +++ b/conformance/results/ty/directives_type_ignore.toml @@ -1,11 +1,6 @@ -conformance_automated = "Fail" -conformant = "Partial" -notes = """ -Treats `# type: ignore[error-code]` as only ignoring errors that match the error code `error-code`. -""" +conformance_automated = "Pass" errors_diff = """ -Line 14: Unexpected errors ['directives_type_ignore.py:14:10: error[invalid-assignment] Object of type `Literal[""]` is not assignable to `int`'] """ output = """ -directives_type_ignore.py:14:10: error[invalid-assignment] Object of type `Literal[""]` is not assignable to `int` +directives_type_ignore.py:16:10: error[invalid-assignment] Object of type `Literal[""]` is not assignable to `int` """ diff --git a/conformance/results/zuban/directives_type_ignore.toml b/conformance/results/zuban/directives_type_ignore.toml index 2e7de839..6d590e85 100644 --- a/conformance/results/zuban/directives_type_ignore.toml +++ b/conformance/results/zuban/directives_type_ignore.toml @@ -1,12 +1,7 @@ -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 +directives_type_ignore.py:16: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] +directives_type_ignore.py:16: 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..b3526e4b 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[an-empty-str-is-not-an-int] # E? # > 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()``