Title: class object typed with Type[SomeAbstractClass] should not complain about instantiation · Issue #1843 · python/mypy · GitHub
Open Graph Title: class object typed with Type[SomeAbstractClass] should not complain about instantiation · Issue #1843 · python/mypy
X Title: class object typed with Type[SomeAbstractClass] should not complain about instantiation · Issue #1843 · python/mypy
Description: I wish this code would work: from typing import Type from abc import ABC, abstractmethod class A(ABC): @abstractmethod def m(self) -> None: pass def f(a: Type[A]) -> A: return a() # E: Cannot instantiate abstract class 'A' with abstract ...
Open Graph Description: I wish this code would work: from typing import Type from abc import ABC, abstractmethod class A(ABC): @abstractmethod def m(self) -> None: pass def f(a: Type[A]) -> A: return a() # E: Cannot insta...
X Description: I wish this code would work: from typing import Type from abc import ABC, abstractmethod class A(ABC): @abstractmethod def m(self) -> None: pass def f(a: Type[A]) -> A: return a() # E: Cannot...
Opengraph URL: https://github.com/python/mypy/issues/1843
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"class object typed with Type[SomeAbstractClass] should not complain about instantiation","articleBody":"I wish this code would work:\n\n```\nfrom typing import Type\n\nfrom abc import ABC, abstractmethod\n\nclass A(ABC):\n @abstractmethod\n def m(self) -> None: pass\n\ndef f(a: Type[A]) -> A:\n return a() # E: Cannot instantiate abstract class 'A' with abstract attribute 'm'\n```\n\nThe obvious intention is to pass f() a concrete subclass of A.\n\n(**UPDATE:** My real-world use case is a bit more involved, in asyncio there are some classes that implement an elaborate ABC, and I'd like to just say `SelectorEventLoop = ... # type: Type[AbstractEventLoop]` rather than having to write out the class definition with all 38 concrete method definitions.)\n","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2016-07-11T20:47:48Z","url":"https://github.com/python/mypy/issues/1843"}
| 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:a065be96-8c7e-a357-21aa-0d0125b038b9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8BE:30CC09:1090BBA:1612174:6AFFBFEB |
| html-safe-nonce | dd7b368f09eab90f81f7f10a7a7f6955ab10d3ecdf764dff952af9e6fe8aaab2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEJFOjMwQ0MwOToxMDkwQkJBOjE2MTIxNzQ6NkFGRkJGRUIiLCJ2aXNpdG9yX2lkIjoiNTI5NTEyNzM3MTY4OTMyODQ0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b152f553a66d2ef7bd7aef45fe10483104b1405a40d0bd6573bc3c997b8369ff |
| hovercard-subject-tag | issue:164930773 |
| 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/1843/issue_layout |
| twitter:image | https://opengraph.githubassets.com/567c046704ac72610f48abd212b122ebf63dc9cd11d5f715dd3baab4621ae92c/python/mypy/issues/1843 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/567c046704ac72610f48abd212b122ebf63dc9cd11d5f715dd3baab4621ae92c/python/mypy/issues/1843 |
| og:image:alt | I wish this code would work: from typing import Type from abc import ABC, abstractmethod class A(ABC): @abstractmethod def m(self) -> None: pass def f(a: Type[A]) -> A: return a() # E: Cannot insta... |
| 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 | 1e805b832df235bb21305db712c3b6432920019dfc12cb25b9cb8d3b0c9403cf |
| 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 | 8fa4a54e6871c7908eda1c246ad5972982c0b59d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width