Title: Callable types are not handled correctly in frozen dataclasses · Issue #12312 · python/mypy · GitHub
Open Graph Title: Callable types are not handled correctly in frozen dataclasses · Issue #12312 · python/mypy
X Title: Callable types are not handled correctly in frozen dataclasses · Issue #12312 · python/mypy
Description: Bug Report Using a frozen dataclass with an attribute typed as a TypeAlias for a Callable results in mypy treating the attribute as the return value. See reproduce for more easy to understand example. To Reproduce from dataclasses import...
Open Graph Description: Bug Report Using a frozen dataclass with an attribute typed as a TypeAlias for a Callable results in mypy treating the attribute as the return value. See reproduce for more easy to understand examp...
X Description: Bug Report Using a frozen dataclass with an attribute typed as a TypeAlias for a Callable results in mypy treating the attribute as the return value. See reproduce for more easy to understand examp...
Opengraph URL: https://github.com/python/mypy/issues/12312
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Callable types are not handled correctly in frozen dataclasses","articleBody":"\u003c!--\r\n If you're new to mypy and you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form\r\n instead.\r\n Please also consider:\r\n\r\n - checking our common issues page: https://mypy.readthedocs.io/en/stable/common_issues.html\r\n - searching our issue tracker: https://github.com/python/mypy/issues to see if\r\n it's already been reported\r\n - asking on gitter chat: https://gitter.im/python/typing\r\n-->\r\n\r\n**Bug Report**\r\n\r\n\u003c!--\r\nNote: If the problem you are reporting is about a specific library function, then the typeshed tracker is better suited\r\nfor this report: https://github.com/python/typeshed/issues\r\n-->\r\n\r\nUsing a frozen dataclass with an attribute typed as a `TypeAlias` for a `Callable` results in mypy treating the attribute as the return value. See reproduce for more easy to understand example.\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom dataclasses import dataclass\r\nfrom typing import Callable, TypeAlias\r\n\r\nFunc: TypeAlias = Callable[..., None]\r\n\r\n@dataclass(frozen=True, eq=False)\r\nclass Foo:\r\n bar: Func\r\n\r\ndef example() -> None:\r\n pass\r\n\r\nFoo(bar=example).bar()\r\n```\r\nresults in\r\n```\r\ntest.py:13:1: error: \"None\" not callable [misc]\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nmypy should pass\r\n\r\n**Actual Behavior**\r\n\r\nRemoving `frozen=True` causes mypy to pass this code.\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.931\r\n- Mypy command-line flags: N/A\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n```\r\npython_version=3.10\r\nplatform=linux\r\nplugins=pydantic.mypy, sqlalchemy.ext.mypy.plugin\r\n\r\nshow_column_numbers=True\r\nshow_error_codes=True\r\n\r\n# show error messages from unrelated files\r\nfollow_imports=normal\r\n\r\n# show errors about unsatisfied imports\r\nignore_missing_imports = False\r\n\r\n# be strict\r\ndisallow_untyped_calls=True\r\nwarn_return_any=True\r\nstrict_optional=True\r\nwarn_no_return=True\r\nwarn_redundant_casts=True\r\nwarn_unused_ignores=True\r\n\r\n# The following are off by default. Flip them on if you feel\r\n# adventurous.\r\ndisallow_untyped_defs=True\r\ncheck_untyped_defs=True\r\n```\r\n- Python version used: 3.10.2\r\n- Operating system and version: Ubuntu 20.04\r\n\r\n\u003c!--\r\nYou can freely edit this text, please remove all the lines\r\nyou believe are unnecessary.\r\n-->\r\n","author":{"url":"https://github.com/uSpike","@type":"Person","name":"uSpike"},"datePublished":"2022-03-08T22:54:15Z","url":"https://github.com/python/mypy/issues/12312"}
| 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:927fc673-1227-fdfc-d7ff-90f1e523de53 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BC70:29A20E:24C7C6B:320D4DD:6B003369 |
| html-safe-nonce | f6685ba3daab5c265f9e856b8c2907952a4b9d4dc24507df8f38ca9d8d340042 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzcwOjI5QTIwRToyNEM3QzZCOjMyMEQ0REQ6NkIwMDMzNjkiLCJ2aXNpdG9yX2lkIjoiNTYyNzY1NTY1MDcxMzU0NzYyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f697dde1d313d5c9dd590d586805a0528abdd404baeec4d32441aeb4ff470633 |
| hovercard-subject-tag | issue:1163245590 |
| 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/12312/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bda51046e6e9d3a05ffd4a02a401216b9003bc640635fe00e758201cd82a9061/python/mypy/issues/12312 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bda51046e6e9d3a05ffd4a02a401216b9003bc640635fe00e758201cd82a9061/python/mypy/issues/12312 |
| og:image:alt | Bug Report Using a frozen dataclass with an attribute typed as a TypeAlias for a Callable results in mypy treating the attribute as the return value. See reproduce for more easy to understand examp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | uSpike |
| 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