René's URL Explorer Experiment


Title: mypy does not honour `open()` overrides from typeshed. · Issue #11193 · python/mypy · GitHub

Open Graph Title: mypy does not honour `open()` overrides from typeshed. · Issue #11193 · python/mypy

X Title: mypy does not honour `open()` overrides from typeshed. · Issue #11193 · python/mypy

Description: Bug Report It seems like mypy is not honoring the typeshed Path.open overrides exactly, as from these I would expect mypy to think the values returned by open was: io.TextIOWrapper for .open("w") io.BufferedWriter for .open("wb") io.File...

Open Graph Description: Bug Report It seems like mypy is not honoring the typeshed Path.open overrides exactly, as from these I would expect mypy to think the values returned by open was: io.TextIOWrapper for .open("w") i...

X Description: Bug Report It seems like mypy is not honoring the typeshed Path.open overrides exactly, as from these I would expect mypy to think the values returned by open was: io.TextIOWrapper for .open("...

Opengraph URL: https://github.com/python/mypy/issues/11193

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mypy does not honour `open()` overrides from typeshed.","articleBody":"\u003c!--\r\n  If you're new to mypy and you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form\r\n  instead.\r\n-->\r\n\r\n**Bug Report**\r\n\r\n\u003c!--\r\nNote: If the problem you are reporting is about a specific library function, then the typeshed tracker is better suited\r\nfor this report: https://github.com/python/typeshed/issues\r\n-->\r\n\r\nIt seems like mypy is not honoring the [typeshed Path.open overrides](https://github.com/python/mypy/blob/v0.910/mypy/typeshed/stdlib/pathlib.pyi#L83-L139) exactly, as from these I would expect mypy to think the values returned by open was:\r\n- `io.TextIOWrapper` for `.open(\"w\")`\r\n- `io.BufferedWriter` for `.open(\"wb\")`\r\n- `io.FileIO` for `.open(\"wb\", buffering=0)`\r\nBut instead, mypy thinks the values returned are:\r\n- `typing.TextIO` for `.open(\"w\")`\r\n- `typing.BinaryIO` for `.open(\"wb\")`\r\n- `typing.BinaryIO` for `.open(\"wb\", buffering=0)`\r\n\r\nThe same is the case for the `open()` builtin.\r\n\r\nI'm reporting this as a mypy issue, because the typing in typeshed looks right to me for the most part, and I can't even tell from typeshed where mypy would be getting `typing.TextIO` from. I will however report a seperate issue against typeshed for mixing the `io.` and `typing.IO` heirarchies in return types, as this is maybe where `typing.BinaryIO` comes from, but even so the other overrides should take precedence as far as I can tell.\r\n\r\n**To Reproduce**\r\n\r\nThe problem can be seen when running mypy on the following code which contain unit tests which run with no errors:\r\n\r\n```python\r\nimport io\r\nimport pathlib\r\nimport tempfile\r\nimport typing\r\nimport unittest\r\n\r\n\r\nclass TestOpen(unittest.TestCase):\r\n    def setUp(self) -> None:\r\n        self._tmp_path = tempfile.TemporaryDirectory()\r\n        self.tmp_path = pathlib.Path(self._tmp_path.name)\r\n        self.tmp_file = self.tmp_path / \"file\"\r\n\r\n    def tearDown(self) -> None:\r\n        self._tmp_path.cleanup()\r\n\r\n    def test_open_text_stream(self) -> None:\r\n        with self.tmp_file.open(\"w\") as text_stream:\r\n            text_io: typing.TextIO = text_stream  # noqa: F841\r\n            text_io_base: io.TextIOBase = text_stream  # noqa: F841\r\n            assert isinstance(text_stream, io.TextIOBase)\r\n\r\n    def test_open_buffered_stream(self) -> None:\r\n        with self.tmp_file.open(\"wb\") as buffered_stream:\r\n            binary_io: typing.BinaryIO = buffered_stream  # noqa: F841\r\n            buffered_io_base: io.BufferedIOBase = buffered_stream  # noqa: F841\r\n            assert isinstance(buffered_stream, io.BufferedIOBase)\r\n\r\n    def test_open_raw_stream(self) -> None:\r\n        with self.tmp_file.open(\"wb\", buffering=0) as raw_stream:\r\n            binary_io: typing.BinaryIO = raw_stream  # noqa: F841\r\n            raw_io_base: io.RawIOBase = raw_stream  # noqa: F841\r\n            assert isinstance(binary_io, io.RawIOBase)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    unittest.main()\r\n```\r\n\r\n**Expected Behavior**\r\n\r\n\u003c!--\r\n  How did you expect your project to behave?\r\n  It’s fine if you’re not sure your understanding is correct.\r\n  Write down what you thought would happen. If you just expected no errors, you can delete this section.\r\n-->\r\n\r\nI expect mypy to not find any errors in the shared code.\r\n\r\n\r\n**Actual Behavior**\r\n\r\n\u003c!--\r\n  Did something go wrong?\r\n  Is something broken, or not behaving as you expected?\r\n-->\r\n\r\nMypy reports the following type errors:\r\n\r\n```\r\n$ poetry run mypy --show-error-codes --show-error-context  test_open_ut.py\r\ntest_open_ut.py: note: In member \"test_open_text_stream\" of class \"TestOpen\":\r\ntest_open_ut.py:20: error: Incompatible types in assignment (expression has type \"TextIO\", variable has type \"TextIOBase\")  [assignment]\r\ntest_open_ut.py:21: error: Subclass of \"TextIO\" and \"TextIOBase\" cannot exist: would have incompatible method signatures  [unreachable]\r\ntest_open_ut.py: note: In member \"test_open_buffered_stream\" of class \"TestOpen\":\r\ntest_open_ut.py:26: error: Incompatible types in assignment (expression has type \"BinaryIO\", variable has type \"BufferedIOBase\")  [assignment]\r\ntest_open_ut.py:27: error: Subclass of \"BinaryIO\" and \"BufferedIOBase\" cannot exist: would have incompatible method signatures  [unreachable]\r\ntest_open_ut.py: note: In member \"test_open_raw_stream\" of class \"TestOpen\":\r\ntest_open_ut.py:32: error: Incompatible types in assignment (expression has type \"BinaryIO\", variable has type \"RawIOBase\")  [assignment]\r\ntest_open_ut.py:33: error: Subclass of \"BinaryIO\" and \"RawIOBase\" cannot exist: would have incompatible method signatures  [unreachable]\r\n```\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n - Mypy version used: 0.910\r\n - Mypy command-line flags: `--show-error-codes --show-error-context`\r\n - Mypy configuration options from `mypy.ini` (and other config files):\r\n    ```\r\n    [mypy]\r\n    # Kept as seperate config file as some plugins don't support pyproject.toml\r\n    # (e.g pydantic.mypy)\r\n    # https://mypy.readthedocs.io/en/stable/config_file.html\r\n    python_version = 3.7\r\n    strict = True\r\n    warn_unreachable = True\r\n    warn_unused_configs = True\r\n    ```\r\n - Python version used: 3.7\r\n - Operating system and version: Fedora 34\r\n\r\nThe code for this can be found [here](https://gitlab.com/aucampia/issues/202109-pythonio/-/tree/issue-mypy_open_typing)\r\n\r\n\r\n\u003c!--\r\nYou can freely edit this text, please remove all the lines\r\nyou believe are unnecessary.\r\n-->","author":{"url":"https://github.com/aucampia","@type":"Person","name":"aucampia"},"datePublished":"2021-09-25T16:28:16Z","url":"https://github.com/python/mypy/issues/11193"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e0779fbe-4799-d91a-0483-90c18f30600b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id92B0:145630:2D08871:3B889BB:6B002070
html-safe-nonce0520fabe22de40fc0463ece3dd39cba7fdf873c0a4e4765e45110f6c20776142
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkIwOjE0NTYzMDoyRDA4ODcxOjNCODg5QkI6NkIwMDIwNzAiLCJ2aXNpdG9yX2lkIjoiMjUxODY1ODYzMTkzNTcyOTc3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacfe750ad92b7998b406af19e577133f943317929669883088347de95159804ad0
hovercard-subject-tagissue:1007136974
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/11193/issue_layout
twitter:imagehttps://opengraph.githubassets.com/321c1c85d1f225c967e5f9f1446ebc3c9e412025e664abb50c15bca31ff44626/python/mypy/issues/11193
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/321c1c85d1f225c967e5f9f1446ebc3c9e412025e664abb50c15bca31ff44626/python/mypy/issues/11193
og:image:altBug Report It seems like mypy is not honoring the typeshed Path.open overrides exactly, as from these I would expect mypy to think the values returned by open was: io.TextIOWrapper for .open("w") i...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaucampia
hostnamegithub.com
expected-hostnamegithub.com
None4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0
turbo-cache-controlno-preview
go-importgithub.com/python/mypy git https://github.com/python/mypy.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id7053637
octolytics-dimension-repository_nwopython/mypy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id7053637
octolytics-dimension-repository_network_root_nwopython/mypy
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release44c658b24abf00491fb7ae5f56d42c9f38cbeab2
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/11193#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F11193
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F11193
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fmypy
Reloadhttps://github.com/python/mypy/issues/11193
Reloadhttps://github.com/python/mypy/issues/11193
Reloadhttps://github.com/python/mypy/issues/11193
pythonhttps://github.com/python
mypyhttps://github.com/python/mypy
Codehttps://github.com/python/mypy
Issues2.7k (2.7k)https://github.com/python/mypy/issues
Pull requests546 (546)https://github.com/python/mypy/pulls
Actionshttps://github.com/python/mypy/actions
Projectshttps://github.com/python/mypy/projects
Wikihttps://github.com/python/mypy/wiki
Security and qualityhttps://github.com/python/mypy/security
Insightshttps://github.com/python/mypy/insights
https://github.com/python/mypy
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/11193
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/11193
#9275https://github.com/python/mypy/pull/9275
mypy does not honour open() overrides from typeshed.https://github.com/python/mypy/issues/11193#top
#9275https://github.com/python/mypy/pull/9275
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/aucampia
aucampiahttps://github.com/aucampia
on Sep 25, 2021https://github.com/python/mypy/issues/11193#issue-1007136974
typeshed Path.open overrideshttps://github.com/python/mypy/blob/v0.910/mypy/typeshed/stdlib/pathlib.pyi#L83-L139
herehttps://gitlab.com/aucampia/issues/202109-pythonio/-/tree/issue-mypy_open_typing
aucampiahttps://github.com/aucampia
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
on Sep 25, 2021https://github.com/python/mypy/issues/11193#event-5359933601
aucampiahttps://github.com/aucampia
on Sep 25, 2021https://github.com/python/mypy/issues/11193#event-5359937660
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Sep 25, 2021https://github.com/python/mypy/issues/11193#issuecomment-927149368
https://github.com/aucampia
aucampiahttps://github.com/aucampia
on Sep 25, 2021https://github.com/python/mypy/issues/11193#issuecomment-927159498
@erictrauthttps://github.com/erictraut
https://github.com/aucampia
aucampiahttps://github.com/aucampia
on Sep 25, 2021https://github.com/python/mypy/issues/11193#issuecomment-927160397
python/typeshed#6076https://github.com/python/typeshed/issues/6076
https://github.com/Akuli
Akulihttps://github.com/Akuli
on Sep 25, 2021https://github.com/python/mypy/issues/11193#issuecomment-927165208
#9275https://github.com/python/mypy/pull/9275
hauntsaninjahttps://github.com/hauntsaninja
plugins: delete open plugin #9275https://github.com/python/mypy/pull/9275
on Sep 25, 2021https://github.com/python/mypy/issues/11193#event-5360167994
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Sep 25, 2021https://github.com/python/mypy/issues/11193#issuecomment-927174803
hauntsaninjahttps://github.com/hauntsaninja
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#9275https://github.com/python/mypy/pull/9275
on Feb 9, 2022https://github.com/python/mypy/issues/11193#event-6031855139
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/11193
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/11193
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.