Title: False negative when using magic methods · Issue #8027 · python/mypy · GitHub
Open Graph Title: False negative when using magic methods · Issue #8027 · python/mypy
X Title: False negative when using magic methods · Issue #8027 · python/mypy
Description: Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues Please provide more information to help ...
Open Graph Description: Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues ...
X Description: Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues ...
Opengraph URL: https://github.com/python/mypy/issues/8027
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False negative when using magic methods","articleBody":"Note: if you are reporting a wrong signature of a function or a class in\r\nthe standard library, then the typeshed tracker is better suited\r\nfor this report: https://github.com/python/typeshed/issues\r\n\r\nPlease provide more information to help us understand the issue:\r\n\r\n* Are you reporting a bug, or opening a feature request?\r\n\r\nBug?\r\n\r\n* Please insert below the code you are checking with mypy,\r\n or a mock-up repro if the source is private. We would appreciate\r\n if you try to simplify your case to a minimal repro.\r\n\r\n```python\r\nfrom typing import List\r\nfrom typing import Optional\r\n\r\n\r\nclass CustomClass:\r\n def __getitem__(self, key: str) -> Optional[str]:\r\n pass\r\n\r\n\r\nitems: List[CustomClass] = []\r\n[item[\"a\"].strip() for item in items if item[\"a\"] is not None]\r\n```\r\n\r\nThe one below doesn't type check, as expected:\r\n\r\n\u003cdetails>\r\n\r\n```python\r\nfrom typing import List\r\nfrom typing import Optional\r\n\r\n\r\nclass CustomClass:\r\n def getitem(self, key: str) -> Optional[str]:\r\n pass\r\n\r\n\r\nitems: List[CustomClass] = []\r\n[item.getitem(\"a\").strip() for item in items if item.getitem(\"a\") is not None]\r\n```\r\n\r\n\u003c/details>\r\n\r\n* What is the actual behavior/output?\r\n\r\n```\r\nSuccess: no issues found in 1 source file\r\n```\r\n\r\n* What is the behavior/output you expect?\r\n\r\nIt should not type check, as repeated calls to ``__getitem__`` are not guaranteed to return the same value.\r\n\r\n* What are the versions of mypy and Python you are using?\r\n Do you see the same issue after installing mypy from Git master?\r\n\r\n```\r\n% mypy --version\r\nmypy 0.750+dev.1013b63eac2bef395952f2784fb3390dc181dec7\r\n% python --version\r\nPython 3.7.5\r\n```\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n\r\n``--strict --scripts-are-modules``","author":{"url":"https://github.com/fsouza","@type":"Person","name":"fsouza"},"datePublished":"2019-11-27T20:51:50Z","url":"https://github.com/python/mypy/issues/8027"}
| 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:e6823ccd-0359-d853-9f9f-d5e415b15ce8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95E2:30DBED:34DD585:45D3C6C:6B00381D |
| html-safe-nonce | 6f487e291da1f45b46dbaec32c769916ac9eed30d9da2f5fefabf3352c16dd56 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUUyOjMwREJFRDozNERENTg1OjQ1RDNDNkM6NkIwMDM4MUQiLCJ2aXNpdG9yX2lkIjoiMzA0MjYzOTE5MTczNDIzNzIxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8c3e9d13f114dde50b3d559ec29c103d5412cd293f0cffc424e82c355bc77a58 |
| hovercard-subject-tag | issue:529567642 |
| 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/8027/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7b6494aadddd9d9dbf4a8a7b81bb4fb8e37a36eca2d92cd99a0db4fe46b1f703/python/mypy/issues/8027 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7b6494aadddd9d9dbf4a8a7b81bb4fb8e37a36eca2d92cd99a0db4fe46b1f703/python/mypy/issues/8027 |
| og:image:alt | Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fsouza |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width