Title: [1.16 regression] a cast is both needed and redundant at the same time · Issue #19170 · python/mypy · GitHub
Open Graph Title: [1.16 regression] a cast is both needed and redundant at the same time · Issue #19170 · python/mypy
X Title: [1.16 regression] a cast is both needed and redundant at the same time · Issue #19170 · python/mypy
Description: Bug Report Since 1.16, structlog's package type check fails with: src/structlog/stdlib.py:1160: error: Redundant cast to "MutableMapping[str, Any]" [redundant-cast] ed = p(logger, meth_name, cast(EventDict, ed)) ^ Found 1 error in 1 file...
Open Graph Description: Bug Report Since 1.16, structlog's package type check fails with: src/structlog/stdlib.py:1160: error: Redundant cast to "MutableMapping[str, Any]" [redundant-cast] ed = p(logger, meth_name, cast(E...
X Description: Bug Report Since 1.16, structlog's package type check fails with: src/structlog/stdlib.py:1160: error: Redundant cast to "MutableMapping[str, Any]" [redundant-cast] ed = p(logger, met...
Opengraph URL: https://github.com/python/mypy/issues/19170
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[1.16 regression] a cast is both needed and redundant at the same time","articleBody":"**Bug Report**\n\nSince 1.16, [_structlog_](https://github.com/hynek/structlog#)'s package type check fails with:\n\n```\nsrc/structlog/stdlib.py:1160: error: Redundant cast to \"MutableMapping[str, Any]\" [redundant-cast]\n ed = p(logger, meth_name, cast(EventDict, ed))\n ^\nFound 1 error in 1 file (checked 1 source file)\n```\n\nIf I remove the cast, I get:\n\n```\nsrc/structlog/stdlib.py:1160: error: Argument 3 has incompatible type \"Mapping[str, Any] | str | bytes | bytearray | tuple[Any, ...]\"; expected\n\"MutableMapping[str, Any]\" [arg-type]\n ed = p(logger, meth_name, ed)\n ^~\nFound 1 error in 1 file (checked 1 source file)\n```\n\nIf I add a reveal_type, I get on both 1.15 \u0026 1.16:\n\n```\nsrc/structlog/stdlib.py:1160: note: Revealed type is \"typing.MutableMapping[builtins.str, Any]\"\nsrc/structlog/stdlib.py:1160: note: Revealed type is \"Union[typing.Mapping[builtins.str, Any], builtins.str, builtins.bytes, builtins.bytearray, builtins.tuple[Any, ...]]\"\n```\n\nSo I guess Mypy got somehow smarter/confused about that?\n\n**To Reproduce**\n\n- `git clone git@github.com:hynek/structlog.git`\n- `git checkout d948027`\n- run `tox -e mypy-pkg`\n\nI really tried to create a minimal reproducer, but given that I don't quite understand what's going on, I've failed.\n\nThe relevant code is here: https://github.com/hynek/structlog/blob/e941e337d312eaf256595d9d09da4542c5e94d0b/src/structlog/stdlib.py#L1160\n\nThe types are defined here: https://github.com/hynek/structlog/blob/e941e337d312eaf256595d9d09da4542c5e94d0b/src/structlog/typing.py#L61-L76\n\n**Expected Behavior**\n\nI would expect it to keep working, or at least decide whether or not I need the cast. 🤓\n\n**Actual Behavior**\n\nI don't seem to find a way to make the code pass except using Any all over the place I guess.\n\n**Your Environment**\n\n- Mypy version used: 1.16\n- Mypy command-line flags: none\n- Mypy configuration options from `mypy.ini` (and other config files): https://github.com/hynek/structlog/blob/e941e337d312eaf256595d9d09da4542c5e94d0b/pyproject.toml#L175-L191\n- Python version used: 3.13\n\n**edit** I managed to [work around it](https://github.com/hynek/structlog/commit/57e165bfacb79eb5942389c20eb9d883d88bfcb6) with the help of @Tinche but it still looks like I managed to break poor little Mypy.","author":{"url":"https://github.com/hynek","@type":"Person","name":"hynek"},"datePublished":"2025-05-30T06:19:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/19170/mypy/issues/19170"}
| 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:c39e05ab-5ae5-07a0-4e00-b6f8f990d253 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC8E:2B8604:1323CC9:1930D89:6A5BD2DF |
| html-safe-nonce | 3cc207db0673cfdbf944368a82805e59ff523aafdda77af08409ba7ee20c8245 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzhFOjJCODYwNDoxMzIzQ0M5OjE5MzBEODk6NkE1QkQyREYiLCJ2aXNpdG9yX2lkIjoiNzU3ODg1MzUyOTQyOTQ2Mzc3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 40c0467974aa7731b45480d085b02d85990d4be202f93b99407e09d923663d0e |
| hovercard-subject-tag | issue:3102204942 |
| 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/19170/issue_layout |
| twitter:image | https://opengraph.githubassets.com/75dad96d87035ca10b657c50eda44796e5d6cac56b1f4ee6a30b93569b4ccdd4/python/mypy/issues/19170 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/75dad96d87035ca10b657c50eda44796e5d6cac56b1f4ee6a30b93569b4ccdd4/python/mypy/issues/19170 |
| og:image:alt | Bug Report Since 1.16, structlog's package type check fails with: src/structlog/stdlib.py:1160: error: Redundant cast to "MutableMapping[str, Any]" [redundant-cast] ed = p(logger, meth_name, cast(E... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hynek |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width