Title: BytesIO.name and StringIO.name should not be defined · Issue #1790 · python/typeshed · GitHub
Open Graph Title: BytesIO.name and StringIO.name should not be defined · Issue #1790 · python/typeshed
X Title: BytesIO.name and StringIO.name should not be defined · Issue #1790 · python/typeshed
Description: Please consider the following Python 3.6 code: from io import BytesIO class NamedBytesIO(BytesIO): def __init__(self, content: bytes, name: str) -> None: super().__init__(content) self.name = name mypy 0.560 complains: test.py:8: error: ...
Open Graph Description: Please consider the following Python 3.6 code: from io import BytesIO class NamedBytesIO(BytesIO): def __init__(self, content: bytes, name: str) -> None: super().__init__(content) self.name = name ...
X Description: Please consider the following Python 3.6 code: from io import BytesIO class NamedBytesIO(BytesIO): def __init__(self, content: bytes, name: str) -> None: super().__init__(content) self.name = na...
Opengraph URL: https://github.com/python/typeshed/issues/1790
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"BytesIO.name and StringIO.name should not be defined","articleBody":"Please consider the following Python 3.6 code:\r\n\r\n```python\r\nfrom io import BytesIO\r\n\r\n\r\nclass NamedBytesIO(BytesIO):\r\n\r\n def __init__(self, content: bytes, name: str) -> None:\r\n super().__init__(content)\r\n self.name = name\r\n```\r\n\r\nmypy 0.560 complains:\r\n\r\n> test.py:8: error: Property \"name\" defined in \"NamedBytesIO\" is read-only\r\n\r\nThis is due to the fact that in typeshed `BytesIO` derives from `BinaryIO`, which defines the `name` property. The actual `BytesIO` implementation does not have such an attribute:\r\n\r\n```\r\n>>> from io import BytesIO\r\n>>> BytesIO(b\"\").name\r\nTraceback (most recent call last):\r\n File \"\u003cstdin>\", line 1, in \u003cmodule>\r\nAttributeError: '_io.BytesIO' object has no attribute 'name'\r\n```\r\n\r\nInterestingly, `StringIO` does not have this problem:\r\n\r\n```python\r\nfrom io import StringIO\r\n\r\n\r\nclass NamedStringIO(StringIO):\r\n\r\n def __init__(self, content: str, name: str) -> None:\r\n super().__init__(content)\r\n self.name = name\r\n```\r\n\r\nThis checks fine with mypy, since the `StringIO` stub includes a `name` field, which also does not match the implementation:\r\n\r\n```\r\n>>> from io import StringIO\r\n>>> StringIO(\"\").name\r\nTraceback (most recent call last):\r\n File \"\u003cstdin>\", line 1, in \u003cmodule>\r\nAttributeError: '_io.StringIO' object has no attribute 'name'\r\n```","author":{"url":"https://github.com/srittau","@type":"Person","name":"srittau"},"datePublished":"2017-12-17T15:28:52Z","url":"https://github.com/python/typeshed/issues/1790"}
| 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:3e891777-d7db-7328-82cd-02766dddcf5c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 867E:1AEC58:1487D1:1B7526:6B001EFA |
| html-safe-nonce | 6d329d33f386433e52a06224e03e40f967a5da17f8fd8a30739e79d93a4cba83 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjdFOjFBRUM1ODoxNDg3RDE6MUI3NTI2OjZCMDAxRUZBIiwidmlzaXRvcl9pZCI6IjI4NzMzOTA1ODA4OTE2NTU5MzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 80a81d60a9c1b38d1029f7a9a15fe10f36355916deb45c9358742253d10106bc |
| hovercard-subject-tag | issue:282701526 |
| 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/1790/issue_layout |
| twitter:image | https://opengraph.githubassets.com/36adb1e46c8859fa6413aa48d9fa01b3447d87f54d3d28b40e0907e1ca510530/python/typeshed/issues/1790 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/36adb1e46c8859fa6413aa48d9fa01b3447d87f54d3d28b40e0907e1ca510530/python/typeshed/issues/1790 |
| og:image:alt | Please consider the following Python 3.6 code: from io import BytesIO class NamedBytesIO(BytesIO): def __init__(self, content: bytes, name: str) -> None: super().__init__(content) self.name = name ... |
| 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 | 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