Title: [1.20 regression] mypy no longer detects variable type narrowing via reassignment · Issue #21273 · python/mypy · GitHub
Open Graph Title: [1.20 regression] mypy no longer detects variable type narrowing via reassignment · Issue #21273 · python/mypy
X Title: [1.20 regression] mypy no longer detects variable type narrowing via reassignment · Issue #21273 · python/mypy
Description: Bug Report Mypy v1.20.0 no longer detects variable type narrowing via reassignment in this case. To Reproduce from typing import Iterable def foo(args: Iterable[str | int] | str | int) -> Iterable[str]: if isinstance(args, (str, int)): a...
Open Graph Description: Bug Report Mypy v1.20.0 no longer detects variable type narrowing via reassignment in this case. To Reproduce from typing import Iterable def foo(args: Iterable[str | int] | str | int) -> Iterable[...
X Description: Bug Report Mypy v1.20.0 no longer detects variable type narrowing via reassignment in this case. To Reproduce from typing import Iterable def foo(args: Iterable[str | int] | str | int) -> Iterab...
Opengraph URL: https://github.com/python/mypy/issues/21273
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[1.20 regression] mypy no longer detects variable type narrowing via reassignment","articleBody":"**Bug Report**\n\nMypy v1.20.0 no longer detects variable type narrowing via reassignment in this case.\n\n**To Reproduce**\n\n```python\nfrom typing import Iterable\n\ndef foo(args: Iterable[str | int] | str | int) -> Iterable[str]:\n if isinstance(args, (str, int)):\n args = (args,)\n args = (\n arg if isinstance(arg, str) else str(arg)\n for arg in args\n )\n return args\n```\n- With mypy 1.19.1: https://mypy-play.net/?mypy=1.19.1&python=3.14&gist=b8a1cf65bb99945451f64e846e18f245\n- With mypy 1.20.0: https://mypy-play.net/?mypy=1.20.0&python=3.14&gist=b8a1cf65bb99945451f64e846e18f245\n\n**Expected Behavior**\n\nI expect this code to type check successfully with mypy 1.20.0 like it did with 1.19.1\n\n**Actual Behavior**\n\n```\nmain.py:10: error: Incompatible return value type (got \"Generator[str | int, None, None]\", expected \"Iterable[str]\") [return-value]\n```\n\n**Your Environment**\n\n- Mypy version used: 1.19.1 and 1.20.0\n- Python version used: 3.14\n","author":{"url":"https://github.com/abrahammurciano","@type":"Person","name":"abrahammurciano"},"datePublished":"2026-04-20T13:58:12Z","url":"https://github.com/python/mypy/issues/21273"}
| 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:f9fb1e6e-a00f-87fc-e211-f1f2cf79de79 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BDB6:2DCAE8:1BFD3B7:25EC3DA:6B000860 |
| html-safe-nonce | 480264387c21939e247c70792c39e0909ea1f2196824cae4ecbeaa112a89d58e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCREI2OjJEQ0FFODoxQkZEM0I3OjI1RUMzREE6NkIwMDA4NjAiLCJ2aXNpdG9yX2lkIjoiNzUxNDQ1ODU0MzYwNTQxODA4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7d51d5c5a9da7338ba46c11120433d0c3e12612a802c8dbbdb90fd134e405cc7 |
| hovercard-subject-tag | issue:4296234029 |
| 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/21273/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f12107fa3e5e9cbd0074b301585b5c782eb960a482cd52007c8a69c8e9a34de2/python/mypy/issues/21273 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f12107fa3e5e9cbd0074b301585b5c782eb960a482cd52007c8a69c8e9a34de2/python/mypy/issues/21273 |
| og:image:alt | Bug Report Mypy v1.20.0 no longer detects variable type narrowing via reassignment in this case. To Reproduce from typing import Iterable def foo(args: Iterable[str | int] | str | int) -> Iterable[... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | abrahammurciano |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width