Title: Cannot infer type argument from overloaded function with explicit self types · Issue #14943 · python/mypy · GitHub
Open Graph Title: Cannot infer type argument from overloaded function with explicit self types · Issue #14943 · python/mypy
X Title: Cannot infer type argument from overloaded function with explicit self types · Issue #14943 · python/mypy
Description: This generates a false positive: from typing import IO, Generic, AnyStr, overload from _typeshed import SupportsRead, SupportsWrite class C(Generic[AnyStr]): @overload def write(self: C[str], s: str) -> int: ... @overload def write(self:...
Open Graph Description: This generates a false positive: from typing import IO, Generic, AnyStr, overload from _typeshed import SupportsRead, SupportsWrite class C(Generic[AnyStr]): @overload def write(self: C[str], s: st...
X Description: This generates a false positive: from typing import IO, Generic, AnyStr, overload from _typeshed import SupportsRead, SupportsWrite class C(Generic[AnyStr]): @overload def write(self: C[str], s: st...
Opengraph URL: https://github.com/python/mypy/issues/14943
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot infer type argument from overloaded function with explicit self types","articleBody":"This generates a false positive:\r\n```py\r\nfrom typing import IO, Generic, AnyStr, overload\r\n\r\nfrom _typeshed import SupportsRead, SupportsWrite\r\n\r\nclass C(Generic[AnyStr]):\r\n @overload\r\n def write(self: C[str], s: str) -> int: ...\r\n @overload\r\n def write(self: C[bytes], s: bytes) -> int: ...\r\n def write(self, x):\r\n return 0\r\n\r\ndef cp(src: SupportsRead[AnyStr], dst: SupportsWrite[AnyStr]) -> None: ...\r\n\r\ndef g(a: IO[bytes], b: C[bytes]) -> None:\r\n # error: Cannot infer type argument 1 of \"cp\"\r\n cp(a, b)\r\n```\r\n\r\nHere's a real-world example which generates the false positive on master (but doesn't generate one when using mypy 1.1.1):\r\n```py\r\nimport tempfile\r\nimport shutil\r\nfrom typing import IO\r\n\r\ndef f(model_fileobj: IO[bytes]) -> None:\r\n with tempfile.NamedTemporaryFile() as tmp_file:\r\n # error: Cannot infer type argument 1 of \"copyfileobj\"\r\n shutil.copyfileobj(model_fileobj, tmp_file)\r\n```\r\nThis started on failing on master at 85dac76422a285ae9fcaf6c9ffb2c0ab2f774adb. In particular, there were changes to `tempfile` stubs that trigger this issue.\r\n\r\nIf the `write` method is not overloaded, the calls are type checked correctly.\r\n\r\nThis doesn't seem to cause many issues, so I don't consider this a release blocker, but it would still be nice to fix this.","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2023-03-23T11:52:50Z","url":"https://github.com/python/mypy/issues/14943"}
| 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:ff0e614c-d1ab-06ac-fc3b-93b0ee9828d7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C818:29A20E:2434FBB:3143CB0:6B00304E |
| html-safe-nonce | 5d6bfe56faef185ad02dc343111dd92e6af2195f8fc044f650b98fd84b5b79d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODE4OjI5QTIwRToyNDM0RkJCOjMxNDNDQjA6NkIwMDMwNEUiLCJ2aXNpdG9yX2lkIjoiMjA5OTAwODUzMTQ3MzY0MTU1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b735e82542bae297b98f5c94be7a482b5ebdc4b2e0f0c8ee2b35c64c4b0474d9 |
| hovercard-subject-tag | issue:1637388569 |
| 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/mypy/14943/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f8967b8ecfc4f6c8d9d68affc17447f1eae5a12406e9ab6dae626f53f4d0b4f0/python/mypy/issues/14943 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f8967b8ecfc4f6c8d9d68affc17447f1eae5a12406e9ab6dae626f53f4d0b4f0/python/mypy/issues/14943 |
| og:image:alt | This generates a false positive: from typing import IO, Generic, AnyStr, overload from _typeshed import SupportsRead, SupportsWrite class C(Generic[AnyStr]): @overload def write(self: C[str], s: st... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JukkaL |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width