Skip to content
Merged
3 changes: 0 additions & 3 deletions conformance/results/mypy/directives_type_ignore.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]']
"""
2 changes: 1 addition & 1 deletion conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ <h3>Python Type System Conformance Test Results</h3>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;directives_type_ignore</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not honor "# type: ignore" comment if comment includes additional text.</p></span></div></th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not honor "# type: ignore" comment if comment includes additional text.</p></span></div></th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Treats `# type: ignore[error-code]` as only ignoring errors that match the error code `error-code`.</p></span></div></th>
</tr>
Expand Down
9 changes: 1 addition & 8 deletions conformance/results/zuban/directives_type_ignore.toml
Original file line number Diff line number Diff line change
@@ -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
"""
2 changes: 1 addition & 1 deletion conformance/tests/directives_type_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
y: int = "" # type: ignore - additional stuff

# The following type violation should be suppressed.
Comment thread
davidhalter marked this conversation as resolved.
Outdated
z: int = "" # type: ignore[additional_stuff]
z: int = "" # type: ignore[assignment]
Comment thread
carljm marked this conversation as resolved.
Outdated

# > 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
Expand Down
9 changes: 9 additions & 0 deletions docs/spec/directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ other comments and linting markers:

# type: ignore # <comment or other marker>

The form of ``# type: ignore[...]`` may be used to filter errors depending on
the type checker:

- In ``# 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 in ``# type: ignore[my_code1]`` a type checker may suppress the
error only if the error cause matches the error code ``my_code1``.
- ``# type: ignore`` must always suppress all errors.
Comment thread
davidhalter marked this conversation as resolved.
Outdated

.. _`cast`:

``cast()``
Expand Down