Title: Spurious messages for functions as instance attributes · Issue #11776 · python/mypy · GitHub
Open Graph Title: Spurious messages for functions as instance attributes · Issue #11776 · python/mypy
X Title: Spurious messages for functions as instance attributes · Issue #11776 · python/mypy
Description: Bug Report Run this code: from typing import Callable from dataclasses import dataclass @dataclass(frozen=True) class Face: map_to_volume: Callable[[int], int] f = Face(map_to_volume=lambda x: x) f.map_to_volume(5) through mypy 0.920 on ...
Open Graph Description: Bug Report Run this code: from typing import Callable from dataclasses import dataclass @dataclass(frozen=True) class Face: map_to_volume: Callable[[int], int] f = Face(map_to_volume=lambda x: x) f...
X Description: Bug Report Run this code: from typing import Callable from dataclasses import dataclass @dataclass(frozen=True) class Face: map_to_volume: Callable[[int], int] f = Face(map_to_volume=lambda x: x) f...
Opengraph URL: https://github.com/python/mypy/issues/11776
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Spurious messages for functions as instance attributes","articleBody":"**Bug Report**\r\n\r\nRun this code:\r\n```\r\nfrom typing import Callable\r\nfrom dataclasses import dataclass\r\n\r\n\r\n@dataclass(frozen=True)\r\nclass Face:\r\n map_to_volume: Callable[[int], int]\r\n\r\nf = Face(map_to_volume=lambda x: x)\r\n\r\nf.map_to_volume(5)\r\n```\r\nthrough mypy 0.920 on Python 3.10 and get the following output:\r\n```\r\n$ mypy mypy-bug.py\r\nmypy-bug.py:12: error: Invalid self argument \"Face\" to attribute function \"map_to_volume\" with type \"Callable[[int], int]\"\r\nmypy-bug.py:12: error: \"int\" not callable\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n\r\n**Expected Behavior**\r\n\r\n- I'm surprised to see mypy complain about a `self` argument for `map_to_volume`. It's an instance attribute, not a class attribute, so it is not subject to method processing. Python seems to agree, no `self` argument is passed.\r\n- The message about `int` not being callable seems spurious: `f.map_to_volume` is not an `int`.\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.920\r\n- Mypy command-line flags: (none, see above)\r\n- Mypy configuration options from `mypy.ini` (and other config files): (none)\r\n- Python version used: 3.10\r\n- Operating system and version: Linux, Debian testing/unstable\r\n\r\nx-ref: https://github.com/inducer/modepy/pull/45, which tries to remove a `type: ignore` that was necessitated by #9975.","author":{"url":"https://github.com/inducer","@type":"Person","name":"inducer"},"datePublished":"2021-12-17T01:37:13Z","url":"https://github.com/python/mypy/issues/11776"}
| 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:6e737c2f-8198-d0fc-25df-3e8ee392e499 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0DC:1FBEEF:155AB09:1BE2418:6B000C1E |
| html-safe-nonce | 2d5334e211949989198a0b48d70a84760638189457afc72a5517328713c2b12f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMERDOjFGQkVFRjoxNTVBQjA5OjFCRTI0MTg6NkIwMDBDMUUiLCJ2aXNpdG9yX2lkIjoiOTA0NTk2NjYxOTE5MjMzMTI5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 49b192b2c5ba350ef7aabdf846c1db515e62fbb99f531673f1fd41c92167f83a |
| hovercard-subject-tag | issue:1082793139 |
| 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/11776/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e1305a0847770f312a0de3f2ddd520847f2bee2dc024e4c007ba91dba5ab5f66/python/mypy/issues/11776 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e1305a0847770f312a0de3f2ddd520847f2bee2dc024e4c007ba91dba5ab5f66/python/mypy/issues/11776 |
| og:image:alt | Bug Report Run this code: from typing import Callable from dataclasses import dataclass @dataclass(frozen=True) class Face: map_to_volume: Callable[[int], int] f = Face(map_to_volume=lambda x: x) f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | inducer |
| 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