Title: strict equality check fails to detect non-overlap of `str` and `Path` · Issue #16231 · python/mypy · GitHub
Open Graph Title: strict equality check fails to detect non-overlap of `str` and `Path` · Issue #16231 · python/mypy
X Title: strict equality check fails to detect non-overlap of `str` and `Path` · Issue #16231 · python/mypy
Description: Bug Report At runtime, comparing an instance of Path to str seems to be always negative, i.e., they don't overlap in terms of comparison. Using the --strict-equality typically errors in such cases that are non-overlapping and cannot poss...
Open Graph Description: Bug Report At runtime, comparing an instance of Path to str seems to be always negative, i.e., they don't overlap in terms of comparison. Using the --strict-equality typically errors in such cases ...
X Description: Bug Report At runtime, comparing an instance of Path to str seems to be always negative, i.e., they don't overlap in terms of comparison. Using the --strict-equality typically errors in such ca...
Opengraph URL: https://github.com/python/mypy/issues/16231
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"strict equality check fails to detect non-overlap of `str` and `Path`","articleBody":"\r\n**Bug Report**\r\n\r\n\u003c!--\r\nIf you're reporting a problem with a specific library function, the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues\r\n\r\nIf the project you encountered the issue in is open source, please provide a link to the project.\r\n-->\r\n\r\nAt runtime, comparing an instance of `Path` to `str` seems to be always negative, i.e., they don't overlap in terms of comparison.\r\n\r\nUsing the `--strict-equality` typically errors in such cases that are non-overlapping and cannot possibly yield `True`. This mechanism doesn't seem to work for `Path` and `str`, allowing to silently let such bugs pass.\r\n\r\n**To Reproduce**\r\n\r\nThe following code has a bug, because the `Path` to `str` does not work as intended\r\n\r\n```python\r\nfrom pathlib import Path\r\n\r\na = \"/foo\"\r\nb = Path(\"/foo\")\r\n\r\nif a == b: # can never be true\r\n ...\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nI'd have expected a type error similar to the one for comparing e.g. `str` to `int`:\r\n\r\n```\r\nerror: Non-overlapping equality check (left operand type: \"str\", right operand type: \"Path\") [comparison-overlap]\r\n```\r\n\r\n**Actual Behavior**\r\n\r\n`--strict-equality` has no effect here, and misses the bug.\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: 1.5.1\r\n- Mypy command-line flags: `--strict-equality`\r\n- Mypy configuration options from `mypy.ini` (and other config files): -\r\n- Python version used: 3.11\r\n","author":{"url":"https://github.com/bluenote10","@type":"Person","name":"bluenote10"},"datePublished":"2023-10-06T08:58:06Z","url":"https://github.com/python/mypy/issues/16231"}
| 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:f22172c4-4e70-3ea8-83ba-224ec71631df |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9192:27AD12:29E4A4:388280:6B002544 |
| html-safe-nonce | e9b294d97131daee6cbbf8653778a409ec88cff2a4d4e5de434b5a14ed003509 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTkyOjI3QUQxMjoyOUU0QTQ6Mzg4MjgwOjZCMDAyNTQ0IiwidmlzaXRvcl9pZCI6IjkwODY2MzUxMTkwNTczMTUxNDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b52a9c03f69387c5e64a85d82b56b046101b18e79fe29e00aeb066ec9cb4200a |
| hovercard-subject-tag | issue:1929727319 |
| 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/16231/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a861e3e6c00ea05af92cee78fe935937667ec59c63a98a8bafa524c9f0388156/python/mypy/issues/16231 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a861e3e6c00ea05af92cee78fe935937667ec59c63a98a8bafa524c9f0388156/python/mypy/issues/16231 |
| og:image:alt | Bug Report At runtime, comparing an instance of Path to str seems to be always negative, i.e., they don't overlap in terms of comparison. Using the --strict-equality typically errors in such cases ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bluenote10 |
| 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