You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adverse interaction between unreachable code, type: ignore[...], and pass or ... #16232
deffunc1(value: int) ->None:
ifnotisinstance(value, int):
pass# type: ignore[unreachable] # error: [unused-ignore]print("there was a problem ...") # error: [unreachable]
Changing pass to a literal ellipsis (...) also reproduces this problem.
(Motivation: since # type: ignore[...] directives must appear on the same line they affect, placing the # type directive on a pass statement can avoid very long lines.)
Expected Behavior
mypy should treat pass as the unreachable statement in this case.
Actual Behavior
mypy's output is:
main.py:3: error: Unused "type: ignore" comment [unused-ignore]
main.py:4: error: Statement is unreachable [unreachable]
Found 2 errors in 1 file (checked 1 source file)
I also ran into this problem and wanted to share the use case leading me to this issue. Let's assume we have a Python module that contains pytest test cases. We want to skip all test cases in the module, so we use pytest.skip as follows:
importpytestpytest.skip("Skip tests due to XYZ", allow_module_level=True)
deftest_abc() ->None:
...
Mypy will report that the line after pytest.skip is unreachable. However, adding type: ignore[unreachable] simply converts the warning into unused-ignore, as reported by the OP.
As a workaround, I was able to add type: ignore[unreachable, unused-ignore]. This is obviously no big deal, but the behavior is a bit surprising.
Activity
seifertm commentedon Dec 4, 2025
I also ran into this problem and wanted to share the use case leading me to this issue. Let's assume we have a Python module that contains pytest test cases. We want to skip all test cases in the module, so we use pytest.skip as follows:
Mypy will report that the line after pytest.skip is unreachable. However, adding
type: ignore[unreachable]simply converts the warning intounused-ignore, as reported by the OP.As a workaround, I was able to add
type: ignore[unreachable, unused-ignore]. This is obviously no big deal, but the behavior is a bit surprising.Avoid treating pass/... as no-op for reachability
Avoid treating `pass` and `...` as no-op for reachability (python#20488)