Title: [Add test case] Bug in return type of `deque.copy()` in generic type · Issue #12641 · python/mypy · GitHub
Open Graph Title: [Add test case] Bug in return type of `deque.copy()` in generic type · Issue #12641 · python/mypy
X Title: [Add test case] Bug in return type of `deque.copy()` in generic type · Issue #12641 · python/mypy
Description: Bug Report Mypy reasons incorrectly about the return type of collections.deque.copy() if the item type is a generic with a type parameter inside a generic class. To Reproduce from collections import deque from typing import Any, Callable...
Open Graph Description: Bug Report Mypy reasons incorrectly about the return type of collections.deque.copy() if the item type is a generic with a type parameter inside a generic class. To Reproduce from collections impor...
X Description: Bug Report Mypy reasons incorrectly about the return type of collections.deque.copy() if the item type is a generic with a type parameter inside a generic class. To Reproduce from collections impor...
Opengraph URL: https://github.com/python/mypy/issues/12641
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Add test case] Bug in return type of `deque.copy()` in generic type","articleBody":"\r\n**Bug Report**\r\n\r\nMypy reasons incorrectly about the return type of `collections.deque.copy()` if the item type is a generic with a type parameter inside a generic class.\r\n\r\n\r\n\r\n**To Reproduce**\r\n\r\n```py\r\nfrom collections import deque\r\nfrom typing import Any, Callable, Generic, List, Protocol, TypeVar\r\n\r\nT = TypeVar(\"T\")\r\n\r\ndef test(item_type: T) -> None:\r\n a: deque[List[T]] = deque()\r\n b: deque[List[T]] = a.copy() # ok\r\n\r\n\r\nclass Test(Generic[T]):\r\n def test(self) -> None:\r\n a: deque[List[T]] = deque()\r\n b: deque[List[T]] = a.copy() # error: Incompatible types in assignment (expression has type \"deque[List[List[T]]]\", variable has type \"deque[List[T]]\") [assignment]\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nThe return type in the above example should be `List[T]` not `List[List[T]]`.\r\n\r\n\r\n\u003c!--\r\n How did you expect your project to behave?\r\n It’s fine if you’re not sure your understanding is correct.\r\n Write down what you thought would happen. If you just expected no errors, you can delete this section.\r\n-->\r\n\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: 0.942\r\n- Mypy command-line flags: `mypy test.py`\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n ```toml\r\n [tool.mypy]\r\n strict = true\r\n namespace_packages = true\r\n ignore_missing_imports = true\r\n show_error_codes = true\r\n exclude = \"tests\"\r\n ```\r\n\r\n- Python version used: 3.10.2\r\n- Operating system and version: OSX 12.2.1 Monterey\r\n\r\n\u003c!--\r\nYou can freely edit this text, please remove all the lines\r\nyou believe are unnecessary.\r\n-->\r\n","author":{"url":"https://github.com/NiklasRosenstein","@type":"Person","name":"NiklasRosenstein"},"datePublished":"2022-04-21T09:06:51Z","url":"https://github.com/python/mypy/issues/12641"}
| 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:7533c69d-1998-6e01-4039-55788e7d59ff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEE2:1EE55B:1FD900E:2B9E8C3:6B00255A |
| html-safe-nonce | fe2cc1bed17d5c9f09ce660b51b68aae9807693b22c46eb604e600a11842ec7e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUUyOjFFRTU1QjoxRkQ5MDBFOjJCOUU4QzM6NkIwMDI1NUEiLCJ2aXNpdG9yX2lkIjoiNDc1MzE3MjkwMzA2MTYyODI1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 99989bf05471487d9d0533811a066d39746df0e9ed13478ec381d4d8a15df173 |
| hovercard-subject-tag | issue:1210737251 |
| 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/12641/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a0bfebba559f036d6938b531367d9551a97db05e558fa7c1aeba14f207b24a0f/python/mypy/issues/12641 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a0bfebba559f036d6938b531367d9551a97db05e558fa7c1aeba14f207b24a0f/python/mypy/issues/12641 |
| og:image:alt | Bug Report Mypy reasons incorrectly about the return type of collections.deque.copy() if the item type is a generic with a type parameter inside a generic class. To Reproduce from collections impor... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NiklasRosenstein |
| 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