Title: Option to report `deprecated` only for symbols defined in selected packages (inverse of `deprecated_calls_exclude`) · Issue #22026 · python/mypy · GitHub
Open Graph Title: Option to report `deprecated` only for symbols defined in selected packages (inverse of `deprecated_calls_exclude`) · Issue #22026 · python/mypy
X Title: Option to report `deprecated` only for symbols defined in selected packages (inverse of `deprecated_calls_exclude`) · Issue #22026 · python/mypy
Description: Feature Add a way to report [deprecated] only for deprecated symbols defined in selected packages, the inverse of deprecated_calls_exclude: [tool.mypy] enable_error_code = ["deprecated"] deprecated_calls_include = ["mylib"] With this, us...
Open Graph Description: Feature Add a way to report [deprecated] only for deprecated symbols defined in selected packages, the inverse of deprecated_calls_exclude: [tool.mypy] enable_error_code = ["deprecated"] deprecated...
X Description: Feature Add a way to report [deprecated] only for deprecated symbols defined in selected packages, the inverse of deprecated_calls_exclude: [tool.mypy] enable_error_code = ["deprecated"] ...
Opengraph URL: https://github.com/python/mypy/issues/22026
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Option to report `deprecated` only for symbols defined in selected packages (inverse of `deprecated_calls_exclude`)","articleBody":"**Feature**\n\nAdd a way to report `[deprecated]` only for deprecated symbols *defined* in selected packages, the inverse of `deprecated_calls_exclude`:\n\n```toml\n[tool.mypy]\nenable_error_code = [\"deprecated\"]\ndeprecated_calls_include = [\"mylib\"]\n```\n\nWith this, using `mylib.old_func` anywhere (in `mylib` itself, its tests, its examples) is an error, while deprecations defined in third-party packages or the stdlib are not reported. Matching would work exactly like `deprecated_calls_exclude` (prefix on the fully qualified name of the definition), and `deprecated_calls_exclude` would still apply on top of it, so `mylib` can be included while `mylib.compat` is excluded.\n\n**Pitch**\n\nThis is the use case of a library that deprecates its own API:\n\n1. Its own code must never use its own deprecated symbols. Otherwise it ships code that emits `DeprecationWarning`s that downstream users can do nothing about. This should fail CI.\n2. Deprecations in its dependencies must NOT fail CI. Libraries are tested against dependency ranges, so a new upstream release that adds a `@deprecated` breaks every unrelated PR on the next CI run. Often the fix is not even possible yet: when the replacement only exists in the release that deprecated the old name, switching to it means raising the lower bound of the dependency, which is a decision of its own.\n\nAt runtime we already get exactly this split with a pytest `filterwarnings = [\"error:.*mylib\\..* is deprecated:DeprecationWarning\"]` entry. Statically, none of the current options can express it:\n\n- `report_deprecated_as_note` is global: it makes our own deprecations non-fatal too.\n- Per-module overrides select the module being *checked*, not the module that *defines* the deprecated symbol, so they can't tell the two cases apart.\n- `deprecated_calls_exclude` can, but only by listing every dependency. That list has to include transitive packages reached through inheritance (a deprecated method inherited from a base class in another package is reported with that package's fully qualified name), test-only dependencies, and one entry per distribution when several share a namespace package (in our case a family of libraries sharing the `frequenz.*` namespace, so excluding `frequenz` would hide our own deprecations as well). The list has to be updated whenever dependencies change, and forgetting an entry brings back the exact CI break it is meant to prevent. An include list, on the other hand, is a single entry that never changes.\n\n`deprecated_calls_exclude` was added (#18641) for the opposite use case: a library excluding *its own* package because its tests exercise its deprecated API (#18435, and [this comment](https://github.com/python/mypy/pull/18192#issuecomment-2512775035) in #18192). Both cases seem common for libraries, and only this one has no reasonable configuration today.\n\nThe change should be small: it touches the two places that check `deprecated_calls_exclude`, [`TypeChecker.warn_deprecated`](https://github.com/python/mypy/blob/3b28c290153651fc14aef3c1a607d1119faebb35/mypy/checker.py#L8620-L8634) and [`TypeAnalyser.check_and_warn_deprecated`](https://github.com/python/mypy/blob/3b28c290153651fc14aef3c1a607d1119faebb35/mypy/typeanal.py#L842-L859), plus the option, docs and tests. I'd be happy to send a PR if this is acceptable.\n\nA possible generalization is a per-package severity. An include list makes dependency deprecations silent, but what would fit even better is keeping them visible but non-fatal, for example with `report_deprecated_as_note = true` plus a way to report `mylib` as an error anyway. That is close to what @JelleZijlstra suggested in https://github.com/python/mypy/issues/18435#issuecomment-2583224400 (a pattern mapped to a behavior, such as `ignore`, `note` or `error`); `deprecated_calls_include` would then be the special case \"everything else is ignored\". I know notes without errors were questioned in [#18192](https://github.com/python/mypy/pull/18192#issuecomment-2511907869), so I'm not attached to this part and it could be split into a separate issue; the include list alone already solves the CI problem.\n\nHaving something like this might also make it easier to enable `deprecated` by default, as announced in the 1.14 release notes, since projects could keep deprecations they don't control from failing their checks.\n","author":{"url":"https://github.com/llucax","@type":"Person","name":"llucax"},"datePublished":"2026-09-23T08:30:05Z","url":"https://github.com/python/mypy/issues/22026"}
| 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:779d87f4-d7b5-2e1a-16ab-93ee6f09e5a3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D69A:2148FB:20818F7:2C1DE09:6B001DB6 |
| html-safe-nonce | 08c3f509b070402d3641b6fd2a28c4e4245e9f29efaf218542c52ab94ccaee14 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjlBOjIxNDhGQjoyMDgxOEY3OjJDMURFMDk6NkIwMDFEQjYiLCJ2aXNpdG9yX2lkIjoiNzE1MTE3ODg3OTU4NjAxNjY5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 832c7842213e4a3e80b4c4871d338401fa5faf486a6bb7dbd5cd7ce1d33eadb8 |
| hovercard-subject-tag | issue:5550840111 |
| 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/22026/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f3af4e6036325717996466ef7944103ebafc8c827b077578022f690275acf27f/python/mypy/issues/22026 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f3af4e6036325717996466ef7944103ebafc8c827b077578022f690275acf27f/python/mypy/issues/22026 |
| og:image:alt | Feature Add a way to report [deprecated] only for deprecated symbols defined in selected packages, the inverse of deprecated_calls_exclude: [tool.mypy] enable_error_code = ["deprecated"] deprecated... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | llucax |
| 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