Title: `file_digest.file_digest` signature is overly strict · Issue #12414 · python/typeshed · GitHub
Open Graph Title: `file_digest.file_digest` signature is overly strict · Issue #12414 · python/typeshed
X Title: `file_digest.file_digest` signature is overly strict · Issue #12414 · python/typeshed
Description: Using hashlib.file_digest with a file object obtained via pathlib.Path.open failed to typecheck with a protocol compatibility error: src/create_bundles.py:223: error: Argument 1 to "file_digest" has incompatible type "FileIO"; expected "...
Open Graph Description: Using hashlib.file_digest with a file object obtained via pathlib.Path.open failed to typecheck with a protocol compatibility error: src/create_bundles.py:223: error: Argument 1 to "file_digest" ha...
X Description: Using hashlib.file_digest with a file object obtained via pathlib.Path.open failed to typecheck with a protocol compatibility error: src/create_bundles.py:223: error: Argument 1 to "file_diges...
Opengraph URL: https://github.com/python/typeshed/issues/12414
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`file_digest.file_digest` signature is overly strict","articleBody":"Using `hashlib.file_digest` with a file object obtained via `pathlib.Path.open` failed to typecheck with a protocol compatibility error:\r\n\r\n```\r\nsrc/create_bundles.py:223: error: Argument 1 to \"file_digest\" has incompatible type \"FileIO\"; expected \"_BytesIOLike | _FileDigestFileObj\" [arg-type]\r\nsrc/create_bundles.py:223: note: Following member(s) of \"FileIO\" have conflicts:\r\nsrc/create_bundles.py:223: note: Expected:\r\nsrc/create_bundles.py:223: note: def readinto(self, bytearray, /) -> int\r\nsrc/create_bundles.py:223: note: Got:\r\nsrc/create_bundles.py:223: note: def readinto(self, Buffer, /) -> int | None\r\n```\r\n\r\nI'm reasonably sure this is a `typeshed` issue rather than a `mypy` issue.\r\n\r\nMy first thought was that this looks like an internal inconsistency in `typeshed`, as `_FileDigestFileObj` is declared specifically with `bytearray` rather than the more general `WriteableBuffer` (hence filing the issue here).\r\n\r\nHowever, my second thought was that this signature declaration is presumably as it is because `file_digest` will *specifically* pass a `bytearray` instance to `readinto`, and `bytearray` is compatible with `Buffer`, so `mypy` shouldn't be complaining about that. That means the conflict is presumably on the return type rather than on parameter types.\r\n\r\nThe declared type signature nominally indicates that `file_digest` can't cope with `readinto` returning `None`, and `mypy` is correctly flagging that as inconsistent with the way `typeshed` declares the file and socket IO types (allowing them to return `None` here).\r\n\r\nSearching the typeshed code suggests this particular inconsistency exists across several different IO consumer type declarations: https://github.com/search?q=repo%3Apython%2Ftypeshed%20readinto&type=code","author":{"url":"https://github.com/ncoghlan","@type":"Person","name":"ncoghlan"},"datePublished":"2024-07-23T08:31:15Z","url":"https://github.com/python/typeshed/issues/12414"}
| 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:fb773c24-aa12-df82-952e-6735e9f80f1a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A022:302FC:D7FF37:120D90C:6B0052FC |
| html-safe-nonce | 0fa000745ecc1e801827b37dcfa23a58f8f6d4b894a979744ff8d10ea5d83845 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDIyOjMwMkZDOkQ3RkYzNzoxMjBEOTBDOjZCMDA1MkZDIiwidmlzaXRvcl9pZCI6Ijg1MTc3NTk0ODA4NjIxMDIyNjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 423744f50a7a58360be53031c71a962cff1a46965caaba912954b0f80eb6c21a |
| hovercard-subject-tag | issue:2424594252 |
| 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/typeshed/12414/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f2bbb949840869b8c81c34591176c778cf234b2c96e5c9ec6743c39c55eef375/python/typeshed/issues/12414 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f2bbb949840869b8c81c34591176c778cf234b2c96e5c9ec6743c39c55eef375/python/typeshed/issues/12414 |
| og:image:alt | Using hashlib.file_digest with a file object obtained via pathlib.Path.open failed to typecheck with a protocol compatibility error: src/create_bundles.py:223: error: Argument 1 to "file_digest" ha... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ncoghlan |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width