Title: Discrepancy in behavior of Callable instance fields · Issue #1113 · python/typing · GitHub
Open Graph Title: Discrepancy in behavior of Callable instance fields · Issue #1113 · python/typing
X Title: Discrepancy in behavior of Callable instance fields · Issue #1113 · python/typing
Description: (Expanding from python/typeshed#7520 (comment)) Consider this code: from typing import Callable class X: f: Callable[[], int] g: Callable[["X"], int] reveal_type(X().f()) reveal_type(X().g()) Here is how current type checkers handle it: ...
Open Graph Description: (Expanding from python/typeshed#7520 (comment)) Consider this code: from typing import Callable class X: f: Callable[[], int] g: Callable[["X"], int] reveal_type(X().f()) reveal_type(X().g()) Here ...
X Description: (Expanding from python/typeshed#7520 (comment)) Consider this code: from typing import Callable class X: f: Callable[[], int] g: Callable[["X"], int] reveal_type(X().f()) reveal_type(X()....
Opengraph URL: https://github.com/python/typing/issues/1113
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Discrepancy in behavior of Callable instance fields","articleBody":"(Expanding from https://github.com/python/typeshed/pull/7520#issuecomment-1074049966)\r\n\r\nConsider this code:\r\n\r\n```python\r\nfrom typing import Callable\r\n\r\nclass X:\r\n f: Callable[[], int]\r\n g: Callable[[\"X\"], int]\r\n\r\nreveal_type(X().f())\r\nreveal_type(X().g())\r\n```\r\n\r\nHere is how current type checkers handle it:\r\n* pyright complains about the second call (`Expected 1 more positional argument`)\r\n* pytype complains about the second call (`Function \u003ccallable> expects 1 arg(s), got 0 [wrong-arg-count]`)\r\n* pyanalyze complains about the second call (`Missing required positional argument: '__arg0' (code: incompatible_call)`)\r\n* pyre accepts both calls (I think there's a bug where it doesn't complain about missing arguments?)\r\n* mypy complains about the first one (`main.py:8: error: Attribute function \"f\" with type \"Callable[[], int]\" does not accept self argument`).\r\n\r\nI feel like mypy is wrong here, because the behavior where `self` gets implicitly bound on instances is specific to functions, not all callables. But the type system sometimes conflates functions with callables, so I can see where mypy is coming from.\r\n\r\nIn either case, the discrepancy is unfortunate because it means we can't write typeshed stubs that satisfy both type checkers. We should come to an agreement on the right behavior and document it.\r\n\r\n@Akuli pointed out a workaround for mypy's behavior: using a callable protocol (https://github.com/python/typeshed/pull/7520#issuecomment-1074342718)","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2022-03-22T15:21:28Z","url":"https://github.com/python/typing/issues/1113"}
| 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:90e420ae-3132-db66-6fd7-9e932f704325 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B804:3204C8:2592183:30E48FA:6AFFF7B4 |
| html-safe-nonce | 86b6e7a5f2ef3691e1c73ceda0a3a33281111bca2dcbf8e9e00101d6d4b7d7d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODA0OjMyMDRDODoyNTkyMTgzOjMwRTQ4RkE6NkFGRkY3QjQiLCJ2aXNpdG9yX2lkIjoiNDQwNjEzNDQ5MDM2ODMwOTE3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9b2a5090cc22fda37f85498f20d8827d2541d572088d14ee4f6b55de4c111ec3 |
| hovercard-subject-tag | issue:1176949098 |
| 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/typing/1113/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9e8ef52f34c3e661550b4f16f8835e0894d28685231a73998ed4f26dc487c4a4/python/typing/issues/1113 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9e8ef52f34c3e661550b4f16f8835e0894d28685231a73998ed4f26dc487c4a4/python/typing/issues/1113 |
| og:image:alt | (Expanding from python/typeshed#7520 (comment)) Consider this code: from typing import Callable class X: f: Callable[[], int] g: Callable[["X"], int] reveal_type(X().f()) reveal_type(X().g()) Here ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width