Skip to content

Support namespaced error codes - #22089

Open
ilevkivskyi wants to merge 3 commits into
python:masterfrom
ilevkivskyi:allow-errorcode-ns
Open

ilevkivskyi wants to merge 3 commits into
python:masterfrom
ilevkivskyi:allow-errorcode-ns

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

Apparently some other type checkers do this. So we may do this as well.

@github-actions

This comment has been minimized.

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document this somewhere? I think this is a non-standard feature, even if other tools already support this.

Comment thread mypy/nativeparse.py Outdated
"""Remove mypy: prefix from error codes (if present)."""
normalized = []
for line, codes in ignores:
normalized.append((line, [c.removeprefix("mypy:") for c in codes]))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is a space after the mypy: prefix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space in an error code is rejected at the ast-serialize level.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should we filter out non-mypy prefixes, so that they don't generate warnings about unused ignores?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants