Title: Inconsistent type inference between open() and Path().open() · Issue #2911 · python/typeshed · GitHub
Open Graph Title: Inconsistent type inference between open() and Path().open() · Issue #2911 · python/typeshed
X Title: Inconsistent type inference between open() and Path().open() · Issue #2911 · python/typeshed
Description: I have run into an issue with inconsistent type-inferences for open() and pathlib.Path().open(). I've previously raised this as possible mypy bug #6666. In response to this gvanrossum advised: Right now we have a plugin that special-case...
Open Graph Description: I have run into an issue with inconsistent type-inferences for open() and pathlib.Path().open(). I've previously raised this as possible mypy bug #6666. In response to this gvanrossum advised: Righ...
X Description: I have run into an issue with inconsistent type-inferences for open() and pathlib.Path().open(). I've previously raised this as possible mypy bug #6666. In response to this gvanrossum advised: ...
Opengraph URL: https://github.com/python/typeshed/issues/2911
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent type inference between open() and Path().open() ","articleBody":"I have run into an issue with inconsistent type-inferences for open() and pathlib.Path().open(). \r\n\r\nI've previously raised this as possible mypy bug [#6666](https://github.com/python/mypy/issues/6666). In response to this **gvanrossum** advised: \r\n\r\n> Right now we have a plugin that special-cases builtins.open() but not Path.open(). This should be solved in typeshed by making the definition of Path.open() overloaded on various Literal types. So I am closing this as \"not a mypy bug\" but I recommend that you submit a PR to typeshed to add this.\r\n\r\nSo I am re-raising this issue here. The following snippet demonstrates the issue.\r\n\r\n\r\n\r\n```python\r\n#!/usr/bin/env python3\r\n\r\nfrom pathlib import Path\r\nfp = open('README.rst', 'rt')\r\nprint(type(fp))\r\nfp1 = Path('README.rst').open('rt')\r\nprint(type(fp1))\r\n```\r\nyields:\r\n\r\n```\r\n\u003cclass '_io.TextIOWrapper'>\r\n\u003cclass '_io.TextIOWrapper'>\r\n```\r\n\r\nHowever, running mypy reveal_type on fp and fp1 yields:\r\n\r\n```\r\nRevealed type is 'typing.TextIO'\r\nRevealed type is 'typing.IO[Any]'\r\n```\r\n\r\nI would expect both of these to reveal typing.TextIO. I found this issue when using a routine that switched TextIO output between sys.stdout (TextIO) and a file opened with Path().open() (IO).\r\n\r\nThis is on python 3.7.2 and mypy 0.700.\r\n\r\nI'm happy to develop a PR on this, but it will be a while before I get started and given I've got a bit of learning curve, probably a while longer before I finish. I'm assuming this shouldn't be an issue given I couldn't find any other references to this problem in several hours of combing github issues and the web in general.","author":{"url":"https://github.com/BuongiornoTexas","@type":"Person","name":"BuongiornoTexas"},"datePublished":"2019-04-12T04:28:01Z","url":"https://github.com/python/typeshed/issues/2911"}
| 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:3681abe3-f1df-d3b7-6748-6349546e6fe3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 925E:390AA2:215E76A:2D69C4F:6B0021EC |
| html-safe-nonce | 8bb43d85a1f9a1c3269cc24415dbaa010d9d4cf07422c96c39131c7ff81955bc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjVFOjM5MEFBMjoyMTVFNzZBOjJENjlDNEY6NkIwMDIxRUMiLCJ2aXNpdG9yX2lkIjoiNDU4MTM0MzUzNTU0MTg2NzMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8b2888047b4935e385dac1b9c909cde20fd730b4650a20354ed660274860c325 |
| hovercard-subject-tag | issue:432382142 |
| 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/2911/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c3f9fed7028751df7401f32e4a0655135f9b838d77c490a6b322c8b184e0507e/python/typeshed/issues/2911 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c3f9fed7028751df7401f32e4a0655135f9b838d77c490a6b322c8b184e0507e/python/typeshed/issues/2911 |
| og:image:alt | I have run into an issue with inconsistent type-inferences for open() and pathlib.Path().open(). I've previously raised this as possible mypy bug #6666. In response to this gvanrossum advised: Righ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | BuongiornoTexas |
| 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