Title: IDEA: inheriting from 'Any' should create a new 'Any' type · Issue #567 · python/typing · GitHub
Open Graph Title: IDEA: inheriting from 'Any' should create a new 'Any' type · Issue #567 · python/typing
X Title: IDEA: inheriting from 'Any' should create a new 'Any' type · Issue #567 · python/typing
Description: Currently, in mypy, class M(Any): is an error, because Any is not an actual class. (Note that this is different from class M(A): where A has type Any. I'm talking about explicitly inheriting from Any only here.) In mypy, if we ignore the...
Open Graph Description: Currently, in mypy, class M(Any): is an error, because Any is not an actual class. (Note that this is different from class M(A): where A has type Any. I'm talking about explicitly inheriting from A...
X Description: Currently, in mypy, class M(Any): is an error, because Any is not an actual class. (Note that this is different from class M(A): where A has type Any. I'm talking about explicitly inheriting fr...
Opengraph URL: https://github.com/python/typing/issues/567
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"IDEA: inheriting from 'Any' should create a new 'Any' type","articleBody":"Currently, in mypy, `class M(Any):` is an error, because `Any` is not an actual class. (Note that this is different from `class M(A):` where `A` has type `Any`. I'm talking about explicitly inheriting from `Any` only here.)\r\n\r\nIn mypy, if we ignore the error, we obtain a class that is a subclass of all other classes. (At runtime it still fails, but in a stub file this will work.) Example:\r\n```py\r\nclass M(Any): # type: ignore\r\n pass\r\nclass A: pass\r\ndef foo(a: A): pass\r\nfoo(M()) # No error\r\n```\r\nHowever, `M` does not have the other important property of `Any`, that it is a *superclass* of all other classes. If we add the following to the above example, we get an error:\r\n```py\r\ndef bar(a: M): pass\r\nbar(A()) # error: Argument 1 to \"bar\" has incompatible type \"A\"; expected \"M\"\r\n```\r\nAs a feature, it might be nice to allow explicitly subclassing `Any` and make the resulting class behave more like `Any`, so that the `bar(A())` call above actually works.\r\n\r\nWhy would this be useful? Why not just make `M` an object with type `Any`? Because we can still endow `M` with specific methods, which will be type-checked as usual:\r\n```py\r\nclass M(Any): # type: ignore\r\n def m(self) -> None: pass\r\nM().m() # OK\r\nM().m(12) # error: Too many arguments for \"m\" of \"M\"\r\n```\r\nIf `M` were just an object with type `Any`, we wouldn't get that error.\r\n\r\nReal-world use case: Mock; see the thread started at https://github.com/python/typeshed/pull/2173#issuecomment-396751608.","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2018-06-22T20:35:16Z","url":"https://github.com/python/typing/issues/567"}
| 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:f851b7a8-194a-686f-1f33-4c437045c57a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A4B2:115983:6D876A:92AB18:6B0037CD |
| html-safe-nonce | 698f1ae52b1601915dff8d283e2415e53cf32e80e734e80bfe89bafb56f6f72f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEIyOjExNTk4Mzo2RDg3NkE6OTJBQjE4OjZCMDAzN0NEIiwidmlzaXRvcl9pZCI6IjQ1OTI4Nzk4NjA2NDg2NTIzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6a96253ebf576abbcea1c5c9b7118d566cb852f32e808b8cccaf7044dd126eba |
| hovercard-subject-tag | issue:335011057 |
| 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/typing/567/issue_layout |
| twitter:image | https://opengraph.githubassets.com/24306d4b352a5ff475ae68f6e07ec900b35eeaf453cc762d1ddd5f47d5a23853/python/typing/issues/567 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/24306d4b352a5ff475ae68f6e07ec900b35eeaf453cc762d1ddd5f47d5a23853/python/typing/issues/567 |
| og:image:alt | Currently, in mypy, class M(Any): is an error, because Any is not an actual class. (Note that this is different from class M(A): where A has type Any. I'm talking about explicitly inheriting from A... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gvanrossum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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