Title: tempfile issues · Issue #1780 · python/typeshed · GitHub
Open Graph Title: tempfile issues · Issue #1780 · python/typeshed
X Title: tempfile issues · Issue #1780 · python/typeshed
Description: I would expect the following to work: from tempfile import TemporaryFile from typing import BinaryIO def make_temp() -> BinaryIO: return TemporaryFile() But mypy 0.540 on Python 3.6 complains: foo.py:6: error: Incompatible return value t...
Open Graph Description: I would expect the following to work: from tempfile import TemporaryFile from typing import BinaryIO def make_temp() -> BinaryIO: return TemporaryFile() But mypy 0.540 on Python 3.6 complains: foo....
X Description: I would expect the following to work: from tempfile import TemporaryFile from typing import BinaryIO def make_temp() -> BinaryIO: return TemporaryFile() But mypy 0.540 on Python 3.6 complains: f...
Opengraph URL: https://github.com/python/typeshed/issues/1780
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"tempfile issues","articleBody":"I would expect the following to work:\r\n\r\n```python\r\nfrom tempfile import TemporaryFile\r\nfrom typing import BinaryIO\r\n\r\n\r\ndef make_temp() -\u003e BinaryIO:\r\n return TemporaryFile()\r\n```\r\n\r\nBut mypy 0.540 on Python 3.6 complains:\r\n\r\n```\r\nfoo.py:6: error: Incompatible return value type (got \"IO[Any]\", expected \"BinaryIO\")\r\n```\r\n\r\nI am not sure where exactly the problem is. `TemporaryFile` returns `IO[Any]`. According to https://docs.python.org/3/library/typing.html `BinaryIO` is just an alias for `IO[bytes]`, in which case the above should work, like the following code does:\r\n\r\n```python\r\nfrom tempfile import TemporaryFile\r\nfrom typing import IO\r\n\r\n\r\nMyBinaryIO = IO[bytes]\r\n\r\n\r\ndef make_temp() -\u003e MyBinaryIO:\r\n return TemporaryFile()\r\n```\r\n\r\nBut actually, typing from Python 3.6 derives `BinaryIO` from `IO[bytes]` and adds methods `write()` and `__enter__()`.\r\n\r\nIs this a an issue with the typing implementation of `BinaryIO` or with the documentation? In the latter case, should the return types of `TemporaryFile` et al. be changed to `Union[BinaryIO, StringIO]`?\r\n","author":{"url":"https://github.com/srittau","@type":"Person","name":"srittau"},"datePublished":"2017-12-11T19:07:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1780/typeshed/issues/1780"}
| 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:b3306367-ec6a-b6d3-5bb8-a6e99d551ae5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B396:33D2D8:1D44F24:2A227F2:6A4CE8C1 |
| html-safe-nonce | ea7a5334eac81fd282d60f4f5b7346ac4d66048546850cf189b8e658aafa31df |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzk2OjMzRDJEODoxRDQ0RjI0OjJBMjI3RjI6NkE0Q0U4QzEiLCJ2aXNpdG9yX2lkIjoiMzUwOTQ0MTYwNzgyMzU4MzQyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cec0116d654d4d3b502474edd4e981311694060f3197c783320f49550eea0380 |
| hovercard-subject-tag | issue:281132763 |
| 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/1780/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2388ec53ec41264c7567b66cb0b16c87e870685f0555140f27934d7080953baf/python/typeshed/issues/1780 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2388ec53ec41264c7567b66cb0b16c87e870685f0555140f27934d7080953baf/python/typeshed/issues/1780 |
| og:image:alt | I would expect the following to work: from tempfile import TemporaryFile from typing import BinaryIO def make_temp() -> BinaryIO: return TemporaryFile() But mypy 0.540 on Python 3.6 complains: foo.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | srittau |
| hostname | github.com |
| expected-hostname | github.com |
| None | 299b43bca6e02ad35197ffeba30d2466846d5fb02ab96fbced5b5e6cec589fb8 |
| 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 | c5a57f04eeb310f57c73fd6d751d957e2ca27ed2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width