Title: Cannot assign to field of Callable type · Issue #708 · python/mypy · GitHub
Open Graph Title: Cannot assign to field of Callable type · Issue #708 · python/mypy
X Title: Cannot assign to field of Callable type · Issue #708 · python/mypy
Description: Consider this example: from typing import Callable class A: f = None # type: Callable[[int], int] def __init__(self, g: Callable[[int], int]) -> None: self.f = g mypy reports: trial.py: In member "__init__" of class "A": trial.py, line 7...
Open Graph Description: Consider this example: from typing import Callable class A: f = None # type: Callable[[int], int] def __init__(self, g: Callable[[int], int]) -> None: self.f = g mypy reports: trial.py: In member "...
X Description: Consider this example: from typing import Callable class A: f = None # type: Callable[[int], int] def __init__(self, g: Callable[[int], int]) -> None: self.f = g mypy reports: trial.py: In membe...
Opengraph URL: https://github.com/python/mypy/issues/708
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot assign to field of Callable type","articleBody":"Consider this example:\n\n``` python\nfrom typing import Callable\n\nclass A:\n f = None # type: Callable[[int], int]\n\n def __init__(self, g: Callable[[int], int]) -> None:\n self.f = g\n```\n\nmypy reports:\n\n```\ntrial.py: In member \"__init__\" of class \"A\":\ntrial.py, line 7: Cannot assign to a method\ntrial.py, line 7: Invalid method type\ntrial.py, line 7: Incompatible types in assignment (expression has type Callable[[int], int], variable has type Callable[[], int])\n```\n\nwhile I'd expect this to work.\n\nNote that there is a second error in the reporting of the type of the variable.\n\nAlso, this passes type checking (correctly):\n\n``` python\nf = None # type: Callable[[int], int]\n\ndef g(x: int) -> int: return 0\n\nf = g\n```\n","author":{"url":"https://github.com/spkersten","@type":"Person","name":"spkersten"},"datePublished":"2015-06-06T15:55:51Z","url":"https://github.com/python/mypy/issues/708"}
| 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:8c9814c9-59df-e3d9-8f84-c1614c8cf966 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E184:B0403:EBD24B:1337A0F:6AFFF236 |
| html-safe-nonce | c8d36009e451dad46fcc310587c6593925f79456429134c00557dd587260d2e0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTg0OkIwNDAzOkVCRDI0QjoxMzM3QTBGOjZBRkZGMjM2IiwidmlzaXRvcl9pZCI6Ijc4NjEyODkxNTYxNjc1NjI3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 305e9239f73bbb37c16d61d76982846d2e191053ed38eea650366a6158323962 |
| hovercard-subject-tag | issue:85773757 |
| 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/708/issue_layout |
| twitter:image | https://opengraph.githubassets.com/488180a7f0573c2d1483756a40efa5a50e05c71a3afcd3d820ee159aa26e903a/python/mypy/issues/708 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/488180a7f0573c2d1483756a40efa5a50e05c71a3afcd3d820ee159aa26e903a/python/mypy/issues/708 |
| og:image:alt | Consider this example: from typing import Callable class A: f = None # type: Callable[[int], int] def __init__(self, g: Callable[[int], int]) -> None: self.f = g mypy reports: trial.py: In member "... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | spkersten |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width