Support namespaced error codes - #22089
ilevkivskyi wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
JukkaL
left a comment
There was a problem hiding this comment.
Document this somewhere? I think this is a non-standard feature, even if other tools already support this.
| """Remove mypy: prefix from error codes (if present).""" | ||
| normalized = [] | ||
| for line, codes in ignores: | ||
| normalized.append((line, [c.removeprefix("mypy:") for c in codes])) |
There was a problem hiding this comment.
What happens if there is a space after the mypy: prefix?
There was a problem hiding this comment.
Space in an error code is rejected at the ast-serialize level.
There was a problem hiding this comment.
Btw thinking a bit more about this, we should probably error on an unrecognized code after mypy: prefix. Normally we simply ignore unrecognized codes (to not conflict with other type checkers).
There was a problem hiding this comment.
Also should we filter out non-mypy prefixes, so that they don't generate warnings about unused ignores?
There was a problem hiding this comment.
I thought we are already ignoring all unknown codes, but it looks like we don't. I think we should actually allow all unknown error codes (even if not prefixed), so that x = 1 # type: ignore[foobar] will not generate an unused ignore.
|
Diff from mypy_primer, showing the effect of this PR on open source code: steam.py (https://github.com/Gobot1234/steam.py)
- steam/manifest.py:1216: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/hashing.py:79: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/utilities/visualization.py:192: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/utilities/visualization.py:194: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/utilities/visualization.py:225: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/settings/legacy.py:11: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/futures.py:642: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/blocks/core.py:215: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/flows.py:1927: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/flows.py:2049: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/context.py:51: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/cache_policies.py:120: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/cache_policies.py:251: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/cache_policies.py:388: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/cache_policies.py:405: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/task_engine.py:82: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/task_engine.py:538: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/server/api/server.py:472: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/server/api/server.py:476: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/server/api/server.py:503: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/server/api/server.py:525: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/server/api/server.py:614: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/server/api/server.py:629: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/server/api/server.py:1021: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/cli/deployment.py:76: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/cli/deployment.py:77: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/cli/deployment.py:480: error: Unused "type: ignore" comment [unused-ignore]
operator (https://github.com/canonical/operator)
- ops/main.py:24: error: Unused "type: ignore" comment [unused-ignore]
- ops/main.py:25: error: Unused "type: ignore" comment [unused-ignore]
- ops/main.py:26: error: Unused "type: ignore" comment [unused-ignore]
- ops/main.py:27: error: Unused "type: ignore" comment [unused-ignore]
- ops/testing.py:182: error: Unused "type: ignore" comment [unused-ignore]
beartype (https://github.com/beartype/beartype)
- beartype/_util/cache/utilcachemeta.py:56: error: Unused "type: ignore" comment [unused-ignore]
ibis (https://github.com/ibis-project/ibis)
- ibis/expr/tests/test_schema.py:23: error: Unused "type: ignore" comment [unused-ignore]
- ibis/expr/datatypes/tests/test_core.py:764: error: Unused "type: ignore" comment [unused-ignore]
|
Apparently some other type checkers do this. So we may do this as well.