Title: False positive: comparison-overlap with dataclasses.Field.default_factory and dataclasses.MISSING · Issue #12124 · python/mypy · GitHub
Open Graph Title: False positive: comparison-overlap with dataclasses.Field.default_factory and dataclasses.MISSING · Issue #12124 · python/mypy
X Title: False positive: comparison-overlap with dataclasses.Field.default_factory and dataclasses.MISSING · Issue #12124 · python/mypy
Description: Bug Report In code which is checking if a field has a default, a check to see if Field.default_factory is MISSING will be misreported as a comparison-overlap error if mypy --strict is used. To Reproduce In foo.py: from dataclasses import...
Open Graph Description: Bug Report In code which is checking if a field has a default, a check to see if Field.default_factory is MISSING will be misreported as a comparison-overlap error if mypy --strict is used. To Repr...
X Description: Bug Report In code which is checking if a field has a default, a check to see if Field.default_factory is MISSING will be misreported as a comparison-overlap error if mypy --strict is used. To Repr...
Opengraph URL: https://github.com/python/mypy/issues/12124
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive: comparison-overlap with dataclasses.Field.default_factory and dataclasses.MISSING","articleBody":"**Bug Report**\r\n\r\nIn code which is checking if a field has a default, a check to see if `Field.default_factory is MISSING` will be misreported as a comparison-overlap error if `mypy --strict` is used.\r\n\r\n**To Reproduce**\r\n\r\nIn `foo.py`:\r\n```python\r\nfrom dataclasses import MISSING, Field\r\nfrom typing import Any\r\n\r\ndef is_required(x: Field[Any]) -> bool:\r\n return x.default is MISSING and x.default_factory is MISSING\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nThis check should pass. One of the valid values for `default_factory` is `MISSING`.\r\n\r\n**Actual Behavior**\r\n\r\nWith the above reproduction,\r\n\r\n```shell\r\n$ mypy --strict foo.py\r\nfoo.py:5: error: Non-overlapping identity check (left operand type: \"_DefaultFactory[Any]\", right operand type: \"_MISSING_TYPE\")\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: `0.931` and `master` (`0.940+dev.84b977876aa76bfebf5fe49d11ebd202e4a60a33`)\r\n- Mypy command-line flags: `--strict`\r\n- Mypy configuration options from `mypy.ini` (and other config files): None","author":{"url":"https://github.com/sirosen","@type":"Person","name":"sirosen"},"datePublished":"2022-02-03T23:45:17Z","url":"https://github.com/python/mypy/issues/12124"}
| 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:d044768a-0d6f-8c4a-5952-fdbca1be3896 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E2C0:22E601:B024AB:EBFC7B:6B0049BE |
| html-safe-nonce | 1a4f38de62f4c89579667fb8b472ad9e73fad04070592d9020cd489bb207dd40 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkMwOjIyRTYwMTpCMDI0QUI6RUJGQzdCOjZCMDA0OUJFIiwidmlzaXRvcl9pZCI6Ijg3Nzc0NzI5NzQ5NzU0MjA4NjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 03eecdd97970ee78c6de4375b00a69900455376a3a89382ccbeef3bf949d9da3 |
| hovercard-subject-tag | issue:1123666268 |
| 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/12124/issue_layout |
| twitter:image | https://opengraph.githubassets.com/beaf5b4253c0f15522e7524ca573c874de9d5b94e8abd64bed3250f89e2342eb/python/mypy/issues/12124 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/beaf5b4253c0f15522e7524ca573c874de9d5b94e8abd64bed3250f89e2342eb/python/mypy/issues/12124 |
| og:image:alt | Bug Report In code which is checking if a field has a default, a check to see if Field.default_factory is MISSING will be misreported as a comparison-overlap error if mypy --strict is used. To Repr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sirosen |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width