Title: `type: ignore` comments on imports of external package lead to `[unused-ignore]` error codes every other run · Issue #20105 · python/mypy · GitHub
Open Graph Title: `type: ignore` comments on imports of external package lead to `[unused-ignore]` error codes every other run · Issue #20105 · python/mypy
X Title: `type: ignore` comments on imports of external package lead to `[unused-ignore]` error codes every other run · Issue #20105 · python/mypy
Description: Bug Report When running mypy with --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports, putting a type: ignore[attr-defined] on an import will have mypy report an Unused "type: ignore" comment [unus...
Open Graph Description: Bug Report When running mypy with --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports, putting a type: ignore[attr-defined] on an import will have mypy repor...
X Description: Bug Report When running mypy with --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports, putting a type: ignore[attr-defined] on an import will have mypy repor...
Opengraph URL: https://github.com/python/mypy/issues/20105
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`type: ignore` comments on imports of external package lead to `[unused-ignore]` error codes every other run","articleBody":"\u003c!--\nIf you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form instead.\nPlease consider:\n\n- checking our common issues page: https://mypy.readthedocs.io/en/stable/common_issues.html\n- searching our issue tracker: https://github.com/python/mypy/issues to see if it's already been reported\n- asking on gitter chat: https://gitter.im/python/typing\n-->\n\n**Bug Report**\n\n\u003c!--\nIf you're reporting a problem with a specific library function, the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues\n\nIf the project you encountered the issue in is open source, please provide a link to the project.\n-->\n\nWhen running mypy with ` --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports`, putting a `type: ignore[attr-defined]` on an import will have mypy report an `Unused \"type: ignore\" comment [unused-ignore]` *every other run*, unless the cache is being cleared between runs.\n\n**To Reproduce**\n\n```python\nfrom opentelemetry.instrumentation.asgi import ( # type: ignore[attr-defined]\n OpenTelemetryMiddleware,\n)\n```\n\n(Since this only seems to work with external packages, some setup is required)\n\n1. Run `pip install opentelemetry-instrumentation-asgi opentelemetry-distro`\n2. Add the code snippet below to `file.py`\n3. Run `mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py`: Observer no error\n4. Run `mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py`: Observe an `[unused-ignore]` error\n5. Run `mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py`: Observer no error\n6. Repeat the cycle as many times as you like :)\n\n\nWhen removing the cache between runs, all works well, so I suspect it has *something* to do with caching.\n\n**Your Environment**\n\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\n\n- Mypy version used: `1.18.2`, `main`\n- Mypy command-line flags: `--warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports`\n- Mypy configuration options from `mypy.ini` (and other config files): -\n- Python version used: 3.13.7\n\n\u003c!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->\n","author":{"url":"https://github.com/provinzkraut","@type":"Person","name":"provinzkraut"},"datePublished":"2025-10-23T09:48:12Z","url":"https://github.com/python/mypy/issues/20105"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:eaaaee52-c56d-6103-ee74-90d28e4dfdd4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A860:390AA2:21BC6A3:2DEDCF1:6B0023D5 |
| html-safe-nonce | 53d05faa7784ab1efa0e42f566bec5bf4a7b4322fb21833dec1e0739d23121b4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODYwOjM5MEFBMjoyMUJDNkEzOjJERURDRjE6NkIwMDIzRDUiLCJ2aXNpdG9yX2lkIjoiMjAxMjM1MzM4Mjk3ODY5MjA1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a5be8e591e87906c75604d3eec19e28e7f60331af5fc97f11b66e85e271b94b2 |
| hovercard-subject-tag | issue:3543949415 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/20105/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cb28c03d8e2927a705e5e58229efe22674bda20e9a371bcfea6215830a0ad81e/python/mypy/issues/20105 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cb28c03d8e2927a705e5e58229efe22674bda20e9a371bcfea6215830a0ad81e/python/mypy/issues/20105 |
| og:image:alt | Bug Report When running mypy with --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports, putting a type: ignore[attr-defined] on an import will have mypy repor... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | provinzkraut |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width