Title: Regression of os.scandir() typecheck · Issue #11964 · python/mypy · GitHub
Open Graph Title: Regression of os.scandir() typecheck · Issue #11964 · python/mypy
X Title: Regression of os.scandir() typecheck · Issue #11964 · python/mypy
Description: Bug Report Type variable inference related with os.scandir() seems to generate false-positives. To Reproduce Here is a minimal reproduction example, which is accepted by mypy 0.910 but rejected by 0.930 and 0.931. from __future__ import ...
Open Graph Description: Bug Report Type variable inference related with os.scandir() seems to generate false-positives. To Reproduce Here is a minimal reproduction example, which is accepted by mypy 0.910 but rejected by ...
X Description: Bug Report Type variable inference related with os.scandir() seems to generate false-positives. To Reproduce Here is a minimal reproduction example, which is accepted by mypy 0.910 but rejected by ...
Opengraph URL: https://github.com/python/mypy/issues/11964
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Regression of os.scandir() typecheck","articleBody":"**Bug Report**\r\n\r\n\u003c!--\r\nNote: If the problem you are reporting is about a specific library function, then the typeshed tracker is better suited\r\nfor this report: https://github.com/python/typeshed/issues\r\n-->\r\n\r\nType variable inference related with `os.scandir()` seems to generate false-positives.\r\n\r\n**To Reproduce**\r\n\r\nHere is a minimal reproduction example, which is accepted by mypy 0.910 but rejected by 0.930 and 0.931.\r\n\r\n```python3\r\nfrom __future__ import annotations\r\n\r\nimport os\r\nfrom pathlib import Path\r\n\r\n\r\ndef _calc_usage(target_path: Path | os.DirEntry) -> None:\r\n with os.scandir(target_path) as scanner:\r\n for entry in scanner:\r\n if entry.is_dir():\r\n _calc_usage(target_path)\r\n else:\r\n print('f')\r\n\r\n\r\n_calc_usage(Path('.'))\r\n```\r\n\r\n**Expected Behavior**\r\n\r\n```\r\nSuccess: no issues found in 1 source file\r\n```\r\n\r\n**Actual Behavior**\r\n\r\n```\r\ntest.py:8: error: Value of type variable \"AnyStr\" of \"scandir\" cannot be \"Union[DirEntry[Any], Any]\"\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.931\r\n- Mypy command-line flags: `python -m mypy test.py`\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n- Python version used: 3.9.6\r\n- Operating system and version: macOS 12.1\r\n","author":{"url":"https://github.com/achimnol","@type":"Person","name":"achimnol"},"datePublished":"2022-01-10T15:55:18Z","url":"https://github.com/python/mypy/issues/11964"}
| 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:2a2c099a-66c4-26fd-73ee-c4f0ab3a0638 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B2D0:24D752:C1560E:102F1CA:6B004E9A |
| html-safe-nonce | 3f1e2b103ecd1246559f2ecf77784c4dbc2e1c9947a6d2dcd2339bf8c32fcdb6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkQwOjI0RDc1MjpDMTU2MEU6MTAyRjFDQTo2QjAwNEU5QSIsInZpc2l0b3JfaWQiOiI1MDgzMzkxMTk2MzAzMzk3MzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 314c1685e0c3d837e9c0db44914a46b5dd6feec2d22742afe2926aa5cfe66c31 |
| hovercard-subject-tag | issue:1098063145 |
| 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/11964/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6d1e32395a671fc086d5c4a22faecc04bb33a25d5dea4ce08dc9c3cccb6473c6/python/mypy/issues/11964 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6d1e32395a671fc086d5c4a22faecc04bb33a25d5dea4ce08dc9c3cccb6473c6/python/mypy/issues/11964 |
| og:image:alt | Bug Report Type variable inference related with os.scandir() seems to generate false-positives. To Reproduce Here is a minimal reproduction example, which is accepted by mypy 0.910 but rejected by ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | achimnol |
| 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