I have recently encountered this on 1.0.1. I have not yet produced a minimal example.
In my case the bulk of the unused type: ignore warnings which disappear are on lines that have been typed by the django-stubs project. I wonder if it may have something to do with that project, or with plugins in general.
I have a new example that doesn't have any external requirements.
unused/__init__.py
(empty file)
unused/empty.py
(empty file)
example.py
fromunused.emptyimport*a=1# type: ignore
Instructions (in a clean virtualenv)
$ dmypy stopDaemon stopped
$ dmypy run -- --package example --warn-unused-ignoresDaemon startedexample.py:2: error: Unused "type: ignore" commentFound 1 error in 1 file (checked 46 source files)
$ dmypy run -- --package example --warn-unused-ignoresSuccess: no issues found in 1 source file
From what I can tell this issue happens when we call fine_grained_manager.update([], to_delete) in dmypy_server.Server.fine_grained_increment_follow_imports.
In this case, to_delete is [('unused', '/.../mypy-9655/unused/__init__.py')].
For some reason, when this update is made, the Unused "type: ignore" comment also goes missing.
Next up: dig into mypy, and work out what's going on.
EDIT: I have created a failing test based on this example, and continue to investigate a fix.
@meshy Using #15043, I can confirm that Unused "type: ignore" comment errors seem to appear everytime dmypy is ran, without having to restart the daemon. 👌🏻
The error on line 5 isn't reported on the second step.
The root cause is that we don't report unused type ignores in nodes only processed using reprocess_nodes, i.e. when following fine-grained dependencies or reprocessing nodes that previously generated errors.
I think this is a potential way to fix this (but I haven't thought about this very carefully yet):
Collect a set of all the triggered/processed nodes in propagate_changes_using_dependencies.
At the end of a daemon update, perform the equivalent of generate_unused_ignore_notes, but only report errors within the previously triggered nodes. The filtering step seems necessary, as some parts of modules are often not processed during a fine-grained increment.
Ah, I forgot to mention that the test cases I mentioned above aren't specifically covered by #15043 yet. It's okay to leave fixing these for another PR, but we shouldn't close this issue until all known cases are fixed.
Activity
jgillard commented on Mar 30, 2022
I noticed this today with mypy 0.942, so this is still an issue.
peterbygrave commented on Nov 30, 2022
This is still a problem in 0.991
AlexWaygood commented on Nov 30, 2022
Has anybody managed to find a reproducible example yet?
meshy commented on Feb 20, 2023
I have recently encountered this on 1.0.1. I have not yet produced a minimal example.
In my case the bulk of the unused type: ignore warnings which disappear are on lines that have been typed by the django-stubs project. I wonder if it may have something to do with that project, or with plugins in general.
meshy commented on Feb 27, 2023
meshy commented on Mar 3, 2023
I have a new example that doesn't have any external requirements.
unused/__init__.py
(empty file)
unused/empty.py
(empty file)
example.py
Instructions (in a clean virtualenv)
From what I can tell this issue happens when we call fine_grained_manager.update([], to_delete) in dmypy_server.Server.fine_grained_increment_follow_imports.
In this case, to_delete is [('unused', '/.../mypy-9655/unused/__init__.py')].
For some reason, when this update is made, the Unused "type: ignore" comment also goes missing.
Next up: dig into mypy, and work out what's going on.
EDIT: I have created a failing test based on this example, and continue to investigate a fix.
Add test to demonstrate issue python#9655
Prove ignores without error codes also disappear
Prove ignores without error codes also disappear
Prove possibly-undefined errors disappear
Ensure errors persist after dmypy update
Ensure errors persist after dmypy update
46 remaining items
meshy commented on Jan 2, 2024
If anyone following this thread is able to check if #15043 works for them, I'd appreciate the feedback.
m-honel-ywh2bt commented on Jan 2, 2024
@meshy Using #15043, I can confirm that Unused "type: ignore" comment errors seem to appear everytime dmypy is ran, without having to restart the daemon. 👌🏻
Fix disappearing errors when re-running dmypy check
Add a regression test for type ignores in dmypy
JukkaL commented on Feb 5, 2024
I think there is another case where type ignore comments still aren't being reported. Here are a few failing test cases:
[case testUnusedTypeIgnorePreservedAfterChangeInOtherModule1] # flags: --warn-unused-ignores [file main.py] import a def f() -> None: 1() a = 1 # type: ignore [file a.py] [file a.py.2] x = 1 [out] main.py:4: error: "int" not callable main.py:5: error: Unused "type: ignore" comment == main.py:4: error: "int" not callable main.py:5: error: Unused "type: ignore" comment [case testUnusedTypeIgnorePreservedAfterChangeInOtherModule2] # flags: --warn-unused-ignores [file main.py] import a def f() -> None: 1() a = 1 # type: ignore def g() -> None: 1() # type: ignore [file a.py] [file a.py.2] x = 1 [out] main.py:4: error: "int" not callable main.py:5: error: Unused "type: ignore" comment == main.py:4: error: "int" not callable main.py:5: error: Unused "type: ignore" commentThe error on line 5 isn't reported on the second step.
The root cause is that we don't report unused type ignores in nodes only processed using reprocess_nodes, i.e. when following fine-grained dependencies or reprocessing nodes that previously generated errors.
I think this is a potential way to fix this (but I haven't thought about this very carefully yet):
meshy commented on Feb 5, 2024
@JukkaL good catch.
Do you think this blocks #15043, or could we tackle that case separately?
JukkaL commented on Feb 5, 2024
Ah, I forgot to mention that the test cases I mentioned above aren't specifically covered by #15043 yet. It's okay to leave fixing these for another PR, but we shouldn't close this issue until all known cases are fixed.
meshy commented on Feb 5, 2024
OK great, thank you. I've removed the "fixes" comment from that PR so we avoid closing this issue.
Add test to demonstrate issue python#9655
Prove ignores without error codes also disappear
Prove possibly-undefined errors disappear
Fix disappearing errors when re-running dmypy check
Add a regression test for type ignores in dmypy
Type ignore comments erroneously marked as unused by dmypy (#15043)
Type ignore comments erroneously marked as unused by dmypy (#15043)