Title: `is_dataclass(Any)` return type incorrect, differs from `is_dataclass(object)` · Issue #12401 · python/typeshed · GitHub
Open Graph Title: `is_dataclass(Any)` return type incorrect, differs from `is_dataclass(object)` · Issue #12401 · python/typeshed
X Title: `is_dataclass(Any)` return type incorrect, differs from `is_dataclass(object)` · Issue #12401 · python/typeshed
Description: I found this surprising and arguably incorrect. According to mypy: from typing import Any from dataclasses import is_dataclass def example1(arg: Any) -> None: if is_dataclass(arg): reveal_type(arg) # ❌ Revealed type is "type[_typeshed.Da...
Open Graph Description: I found this surprising and arguably incorrect. According to mypy: from typing import Any from dataclasses import is_dataclass def example1(arg: Any) -> None: if is_dataclass(arg): reveal_type(arg)...
X Description: I found this surprising and arguably incorrect. According to mypy: from typing import Any from dataclasses import is_dataclass def example1(arg: Any) -> None: if is_dataclass(arg): reveal_type(a...
Opengraph URL: https://github.com/python/typeshed/issues/12401
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`is_dataclass(Any)` return type incorrect, differs from `is_dataclass(object)`","articleBody":"I found this surprising and arguably incorrect. According to mypy:\r\n\r\n```python\r\nfrom typing import Any\r\nfrom dataclasses import is_dataclass\r\n\r\n\r\ndef example1(arg: Any) -> None:\r\n if is_dataclass(arg):\r\n reveal_type(arg) # ❌ Revealed type is \"type[_typeshed.DataclassInstance]\"\r\n\r\n\r\ndef example2(arg: object) -> None:\r\n if is_dataclass(arg):\r\n reveal_type(arg) # ✅ Revealed type is \"Union[_typeshed.DataclassInstance, type[_typeshed.DataclassInstance]]\"\r\n```\r\n\r\n[(Mypy playground)](https://mypy-play.net/?mypy=latest&python=3.12&gist=3cb374974a1ca716a0d27c749921ddd4)\r\n\r\nThis is because `Any` matches the 1st overload, even if 2nd overload with `object` argument is more appropriate for `Any`:\r\n\r\n```python\r\n@overload\r\ndef is_dataclass(obj: type) -> TypeIs[type[DataclassInstance]]: ...\r\n@overload\r\ndef is_dataclass(obj: object) -> TypeIs[DataclassInstance | type[DataclassInstance]]: ...\r\n```\r\n\r\nI couldn't think of an elegant fix for this.","author":{"url":"https://github.com/intgr","@type":"Person","name":"intgr"},"datePublished":"2024-07-22T08:39:47Z","url":"https://github.com/python/typeshed/issues/12401"}
| 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:a4851eb7-684e-0923-c5bf-9247d4170d77 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A1B8:1A1C04:251A7FD:32B3543:6B003909 |
| html-safe-nonce | c54017dc5385ed726055c55db8a0384fb1a37e15781d41c76634b9c0a68f1017 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUI4OjFBMUMwNDoyNTFBN0ZEOjMyQjM1NDM6NkIwMDM5MDkiLCJ2aXNpdG9yX2lkIjoiMjMyMDQyNjYwNjgyMjE3NzAzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cfc9c87b1a3b9bdbbbc5d8399fd309af34d5ad1324d1fbc644c0ac0b8cdf3a70 |
| hovercard-subject-tag | issue:2422291120 |
| 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/typeshed/12401/issue_layout |
| twitter:image | https://opengraph.githubassets.com/59fc55e82d9cd13901d8248a5f4888c4f7b64925b8a6ae094a1118534bc3386d/python/typeshed/issues/12401 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/59fc55e82d9cd13901d8248a5f4888c4f7b64925b8a6ae094a1118534bc3386d/python/typeshed/issues/12401 |
| og:image:alt | I found this surprising and arguably incorrect. According to mypy: from typing import Any from dataclasses import is_dataclass def example1(arg: Any) -> None: if is_dataclass(arg): reveal_type(arg)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | intgr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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