Title: Support buffers in `IO[bytes].write` · Issue #9082 · python/typeshed · GitHub
Open Graph Title: Support buffers in `IO[bytes].write` · Issue #9082 · python/typeshed
X Title: Support buffers in `IO[bytes].write` · Issue #9082 · python/typeshed
Description: Trying to annotate psycopg code in order to pass mypy check with disabled bytearray/memoryview promotion to bytes see branch mypy-0990. Everything was smooth, except one questionable point: from typing import IO, Union from typing_extens...
Open Graph Description: Trying to annotate psycopg code in order to pass mypy check with disabled bytearray/memoryview promotion to bytes see branch mypy-0990. Everything was smooth, except one questionable point: from ty...
X Description: Trying to annotate psycopg code in order to pass mypy check with disabled bytearray/memoryview promotion to bytes see branch mypy-0990. Everything was smooth, except one questionable point: from ty...
Opengraph URL: https://github.com/python/typeshed/issues/9082
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support buffers in `IO[bytes].write`","articleBody":"Trying to annotate psycopg code in order to pass mypy check with disabled bytearray/memoryview promotion to bytes [see branch mypy-0990](https://github.com/psycopg/psycopg/tree/mypy-0990).\r\n\r\nEverything was smooth, except one questionable point:\r\n\r\n```python\r\nfrom typing import IO, Union\r\nfrom typing_extensions import TypeAlias\r\n\r\nBuffer: TypeAlias = Union[bytes, bytearray, memoryview]\r\n\r\ndef write1(f: IO[bytes], data: Buffer) -> None:\r\n f.write(data)\r\n```\r\n\r\nMypy 0.990 reports:\r\n\r\n```\r\nerror: Argument 1 to \"write\" of \"IO\" has incompatible type \"Union[bytes, bytearray, memoryview]\"; expected \"bytes\" [arg-type]\r\n```\r\n\r\nSame using `BinaryIO` instead of `IO[bytes]`.\r\n\r\nAs far as I can see, a binary file supports any object supporting the buffer protocol (or maybe less than that? However, the three types in the union tested are definitely supported).\r\n\r\nDeclaring `f: IO[Buffer]` almost works: `write()` doesn't complain anymore, but `IO` does: *Invalid type argument value for \"IO\"*.\r\n\r\nMaybe something could be relaxed here?","author":{"url":"https://github.com/dvarrazzo","@type":"Person","name":"dvarrazzo"},"datePublished":"2022-11-04T02:55:24Z","url":"https://github.com/python/typeshed/issues/9082"}
| 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:c9786b9e-470b-6829-4b4e-203c71d9f66c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EA44:3DAD59:1923A8E:21337A9:6B0023A4 |
| html-safe-nonce | db08fc48f57f8563ebdc5d873b4723721235f36c1d13e5a131d559e05061fe48 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTQ0OjNEQUQ1OToxOTIzQThFOjIxMzM3QTk6NkIwMDIzQTQiLCJ2aXNpdG9yX2lkIjoiMjg5MDUwMTExNjQxODU5Nzc5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cc3079610bd8e5fb96cf685cff8857fb19ae98cd54ed9b453da36697965d2784 |
| hovercard-subject-tag | issue:1435474196 |
| 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/9082/issue_layout |
| twitter:image | https://opengraph.githubassets.com/308e713579796d759844575d8c9e9b62a2b49ea1d9652a510156dbf1aeba3cd3/python/typeshed/issues/9082 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/308e713579796d759844575d8c9e9b62a2b49ea1d9652a510156dbf1aeba3cd3/python/typeshed/issues/9082 |
| og:image:alt | Trying to annotate psycopg code in order to pass mypy check with disabled bytearray/memoryview promotion to bytes see branch mypy-0990. Everything was smooth, except one questionable point: from ty... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dvarrazzo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width