Skip to content

Commit 6ce8087

Browse files
committed
Try to improve the wording for the spec
1 parent f4a919a commit 6ce8087

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

conformance/tests/directives_type_ignore.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
# The following type violation should be suppressed.
1111
y: int = "" # type: ignore - additional stuff
1212

13+
# The following type violations should not be suppressed.
14+
y: int = "" # type: ignored # E: Unexpected word "ignored"
15+
y: int = "" # type: ignored, foo # E: Unexpected comma
16+
1317
# The following type violation should be suppressed.
1418
z: int = "" # type: ignore[assignment]
1519

docs/spec/directives.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,24 @@ other comments and linting markers:
7373

7474
# type: ignore # <comment or other marker>
7575

76-
Any text following ``# type: ignore`` is ignored, provided there is at least one
77-
whitespace character after ``# type: ignore``. The form of
78-
``# type: ignore[error_code1, error_code2]`` can be used to filter error codes
79-
that may vary across type checkers. Type checkers may ignore the bracketed
80-
codes and treat this form as equivalent to ``# type: ignore``.
81-
76+
Text following ``# type: ignore`` must be ignored, provided there is at
77+
least one whitespace character after it::
78+
79+
# Not valid because of the "d" after ignore; does not supress the type error
80+
s: str = 1 # type: ignored
81+
# Not valid because of the comma; does not supress the type error
82+
s: str = 1 # type: ignore, because I feel like it
83+
# This is valid because of the whitespace and must suppress the type error
84+
s: str = 1 # type: ignore because why not
85+
86+
The form of ``# type: ignore[...]`` may be used to filter errors depending on
87+
the type checker:
88+
89+
- In ``# type: ignore[my_code1]``, a type checker may ignore the error code
90+
``my_code1`` and choose to treat this form as equivalent to ``# type: ignore``.
91+
- Alternatively in ``# type: ignore[my_code1]`` a type checker may suppress the
92+
error only if the error cause matches the error code ``my_code1``.
93+
- ``# type: ignore`` must always suppress all errors.
8294

8395
.. _`cast`:
8496

0 commit comments

Comments
 (0)