Title: `del` followed by an assignment of an "incompatible" type shouldn't probably raise an error · Issue #2806 · python/mypy · GitHub
Open Graph Title: `del` followed by an assignment of an "incompatible" type shouldn't probably raise an error · Issue #2806 · python/mypy
X Title: `del` followed by an assignment of an "incompatible" type shouldn't probably raise an error · Issue #2806 · python/mypy
Description: I'm posting this to here because PEP 482--484 didn't seem to mention either "scope" or del and this is probably an implementation detail. Consider this example: x = 1 del x x = "a" Mypy 0.470 raises an error for the above code, saying "I...
Open Graph Description: I'm posting this to here because PEP 482--484 didn't seem to mention either "scope" or del and this is probably an implementation detail. Consider this example: x = 1 del x x = "a" Mypy 0.470 raise...
X Description: I'm posting this to here because PEP 482--484 didn't seem to mention either "scope" or del and this is probably an implementation detail. Consider this example: x = 1 del x x = &q...
Opengraph URL: https://github.com/python/mypy/issues/2806
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`del` followed by an assignment of an \"incompatible\" type shouldn't probably raise an error","articleBody":"I'm posting this to here because PEP 482--484 didn't seem to mention either \"scope\" or `del` and this is probably an implementation detail.\r\n\r\nConsider this example:\r\n\r\n```python\r\nx = 1\r\ndel x\r\nx = \"a\"\r\n```\r\n\r\nMypy 0.470 raises an error for the above code, saying \"Incompatible types in assignment (expression has type \"str\", variable has type \"int\")\". But, shouldn't it be allowed because the `x`s before and after `del` are essentially different variables?\r\n\r\nCompare it with\r\n\r\n```python\r\nx = 1\r\nx = None\r\nx = \"a\"\r\n```\r\n\r\nwhich clearly is a type error (and mypy judges as such.)\r\n\r\nAllowing the 1st pattern will open up the way to conveniently rewrite legacy codes like\r\n\r\n```python\r\n# path: # type str\r\npath = path.split(os.pathsep)\r\n# path: # type List[str]\r\n```\r\n\r\n(taken from [`shutil.py`](https://hg.python.org/cpython/file/tip/Lib/shutil.py#l1122))\r\n\r\nI mean, we will be able to write\r\n\r\n```python\r\npath_ = path.split(os.pathsep)\r\ndel path\r\npath = path_\r\n```","author":{"url":"https://github.com/nodakai","@type":"Person","name":"nodakai"},"datePublished":"2017-02-04T21:48:33Z","url":"https://github.com/python/mypy/issues/2806"}
| 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:9368e47c-7b58-7318-2e91-040002b81adf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BC02:34D604:251F5BE:312C2D2:6B005A4F |
| html-safe-nonce | 7afe27e923552f5ec2ee92d766f3a47bdb8803db78f3a79aed7daa73c36c1f9d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzAyOjM0RDYwNDoyNTFGNUJFOjMxMkMyRDI6NkIwMDVBNEYiLCJ2aXNpdG9yX2lkIjoiNTA3NzQ0OTAyODQ2ODIzNDgzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 714a10ec9ce8ab431eb83748a9be6e35447024c5bb5f2a5e84b9702c0c7efe4a |
| hovercard-subject-tag | issue:205380124 |
| 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/2806/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4fa9296f7ea49e3f1128bc10ebcee7db5ddb6c58dcda09b934cdec400b5da790/python/mypy/issues/2806 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4fa9296f7ea49e3f1128bc10ebcee7db5ddb6c58dcda09b934cdec400b5da790/python/mypy/issues/2806 |
| og:image:alt | I'm posting this to here because PEP 482--484 didn't seem to mention either "scope" or del and this is probably an implementation detail. Consider this example: x = 1 del x x = "a" Mypy 0.470 raise... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nodakai |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| 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 | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width