Title: asyncio tcp transport on Windows reads bytearray instead of bytes · Issue #99941 · python/cpython · GitHub
Open Graph Title: asyncio tcp transport on Windows reads bytearray instead of bytes · Issue #99941 · python/cpython
X Title: asyncio tcp transport on Windows reads bytearray instead of bytes · Issue #99941 · python/cpython
Description: Bug report asyncio.Protocol.data_received prototype not respected: when using create_connection to create a tcp transport data_received is being called with a bytearray object instead of bytes. If this is expected behaviour libraries lik...
Open Graph Description: Bug report asyncio.Protocol.data_received prototype not respected: when using create_connection to create a tcp transport data_received is being called with a bytearray object instead of bytes. If ...
X Description: Bug report asyncio.Protocol.data_received prototype not respected: when using create_connection to create a tcp transport data_received is being called with a bytearray object instead of bytes. If ...
Opengraph URL: https://github.com/python/cpython/issues/99941
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"asyncio tcp transport on Windows reads bytearray instead of bytes","articleBody":"# Bug report\r\n\r\n`asyncio.Protocol.data_received` prototype not respected: when using `create_connection` to create a tcp transport `data_received` is being called with a `bytearray` object instead of `bytes`.\r\nIf this is expected behaviour libraries like httpx and such should be warned or the prototype modified, although I doubt it's intended because it would suppose the generator doesn't hold reference to it otherwise data could change while stored in buffered stuff.\r\n\r\n```python\r\n\r\nimport sys\r\nprint(f'Python: {sys.version}\\n')\r\n\r\nimport asyncio\r\n\r\nclass MyProto(asyncio.Protocol):\r\n def data_received(self, data: bytes) -\u003e None:\r\n print('@@@@@@@@@@ ', data)\r\n def eof_received(self):\r\n print('##########')\r\n\r\nasync def main():\r\n t, proto = await asyncio.get_running_loop().create_connection(MyProto, 'example.com', 80)\r\n t.write(b'SITE BE MAD\\n\\n')\r\n await asyncio.sleep(1)\r\n t.close()\r\n\r\nasyncio.run(main())\r\n\r\n```\r\n\r\nCorrect output: `@@@@@@@@@@ b'HTTP/1.0 ...WHATEVER THE SERVER ANSWERS...'`\r\nFaulty output: `@@@@@@@@@@ bytearray(b'HTTP/1.0 ...WHATEVER THE SERVER ANSWERS...')`\r\n\r\n# Your environment\r\n\r\nOn Windows 11 x64\r\n\r\nTested on:\r\n- 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]\r\n- 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]\r\n\r\nWorking as expected in:\r\n- 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]\r\n\r\n# Related problems\r\n\r\nLink to the thread where I found a conflicting thing (it's being solved there as a workaround)\r\nhttps://github.com/encode/httpx/discussions/2305#discussioncomment-4288553\r\n\r\n**EDIT:** simplified the minimal example\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-100053\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/DarioDaF","@type":"Person","name":"DarioDaF"},"datePublished":"2022-12-02T02:58:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/99941/cpython/issues/99941"}
| 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:f7b203a1-5cf5-02a1-b388-0bec6e0e38cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9058:281585:10B85AA:1776292:696A421A |
| html-safe-nonce | 4b5b4fbf66271da6d5d98d64f36acbd0fad4b901949e1c6484582ff7ecb3f0ba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDU4OjI4MTU4NToxMEI4NUFBOjE3NzYyOTI6Njk2QTQyMUEiLCJ2aXNpdG9yX2lkIjoiMjg5MDgxNjU2ODg1NDk4NzI5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4133dec0254189b11ad2578091804cf1de1b8c977c47b889ef42a27e3733508 |
| hovercard-subject-tag | issue:1472236861 |
| 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/cpython/99941/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a1fc05622c2beda6a96a3a1573c00d02e7b00c743ae466b3bdaa9dad972f6708/python/cpython/issues/99941 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a1fc05622c2beda6a96a3a1573c00d02e7b00c743ae466b3bdaa9dad972f6708/python/cpython/issues/99941 |
| og:image:alt | Bug report asyncio.Protocol.data_received prototype not respected: when using create_connection to create a tcp transport data_received is being called with a bytearray object instead of bytes. If ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DarioDaF |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | 63c426b30d262aba269ef14c40e3c817b384cd61 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width