Title: Class with function fields incorrectly thinks first argument is self · Issue #5485 · python/mypy · GitHub
Open Graph Title: Class with function fields incorrectly thinks first argument is self · Issue #5485 · python/mypy
X Title: Class with function fields incorrectly thinks first argument is self · Issue #5485 · python/mypy
Description: This is a bug report. Minimal repro from dataclasses import dataclass from typing import Callable @dataclass class Repro: fn: Callable[[int], str] r = Repro(fn=repr) assert "1" == r.fn(1) Works correctly when dataclass is not used, i.e. ...
Open Graph Description: This is a bug report. Minimal repro from dataclasses import dataclass from typing import Callable @dataclass class Repro: fn: Callable[[int], str] r = Repro(fn=repr) assert "1" == r.fn(1) Works cor...
X Description: This is a bug report. Minimal repro from dataclasses import dataclass from typing import Callable @dataclass class Repro: fn: Callable[[int], str] r = Repro(fn=repr) assert "1" == r.fn(1)...
Opengraph URL: https://github.com/python/mypy/issues/5485
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Class with function fields incorrectly thinks first argument is self","articleBody":"This is a bug report.\r\n\r\n# Minimal repro\r\n\r\n```python\r\nfrom dataclasses import dataclass\r\nfrom typing import Callable\r\n\r\n@dataclass\r\nclass Repro:\r\n fn: Callable[[int], str]\r\n\r\nr = Repro(fn=repr)\r\nassert \"1\" == r.fn(1)\r\n```\r\n\r\nWorks correctly when dataclass is not used, i.e. when `Repro` is\r\n\r\n```python\r\nclass Repro:\r\n def __init__(self, fn: Callable[[int], str]) -> None:\r\n self.fn = fn\r\n```\r\n\r\n## Actual behavior\r\n\r\n```python\r\nrepro.py:9: error: Invalid self argument \"Repro\" to attribute function \"fn\" with type \"Callable[[int], str]\"\r\nrepro.py:9: error: Too many arguments\r\n```\r\n\r\nWhen running with Python, works correctly. Doesn't throw any exceptions.\r\n\r\n## Expected behavior\r\n\r\nSuccessful type check\r\n\r\n# Environment\r\n\r\n## Versions\r\n\r\nTested with two versions, 0.620 and current version from GitHub.\r\n\r\n* Python 3.7.0\r\n* mypy 0.620\r\n* mypy 0.630+dev-a2ffde90635baf05e264f8d899f5705c52b27c2a\r\n\r\n## Mypy config\r\n\r\n```ini\r\n[mypy]\r\nwarn_redundant_casts = True\r\nwarn_unused_ignores = True\r\nincremental = True\r\n\r\nfollow_imports = normal\r\nignore_missing_imports = True\r\ndisallow_untyped_calls = True\r\ndisallow_untyped_defs = True\r\ncheck_untyped_defs = True\r\nwarn_return_any = True\r\nwarn_no_return = True\r\nno_implicit_optional = True\r\nstrict_optional = True\r\n```\r\n","author":{"url":"https://github.com/Dentosal","@type":"Person","name":"Dentosal"},"datePublished":"2018-08-15T11:31:23Z","url":"https://github.com/python/mypy/issues/5485"}
| 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:93c58888-120c-89da-2aa6-77d8a943b159 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B174:144E47:26063E0:319067E:6AFFF7D8 |
| html-safe-nonce | fb241d5f9b6a6bfe01c428d4d93f97f56e186c2e8bc6163eacfa785ae9d81728 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTc0OjE0NEU0NzoyNjA2M0UwOjMxOTA2N0U6NkFGRkY3RDgiLCJ2aXNpdG9yX2lkIjoiMTQzNTI2NTYxNjk4OTY0ODg1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fc29ba5aca6eacdad4bc63ffa70fc4018c3bd1bff1789714b3436b5a1854aa49 |
| hovercard-subject-tag | issue:350776529 |
| 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/5485/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c18e709c2b5088215d1510ab23f600761b86c05afcdfaf78aa0273cc2e148f6b/python/mypy/issues/5485 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c18e709c2b5088215d1510ab23f600761b86c05afcdfaf78aa0273cc2e148f6b/python/mypy/issues/5485 |
| og:image:alt | This is a bug report. Minimal repro from dataclasses import dataclass from typing import Callable @dataclass class Repro: fn: Callable[[int], str] r = Repro(fn=repr) assert "1" == r.fn(1) Works cor... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Dentosal |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width