Title: Instantiating concrete classes fails check in some cases · Issue #6586 · python/mypy · GitHub
Open Graph Title: Instantiating concrete classes fails check in some cases · Issue #6586 · python/mypy
X Title: Instantiating concrete classes fails check in some cases · Issue #6586 · python/mypy
Description: #1843/#2853 added support for instantiating variables with an abstract type, under the assumption that it will always be applied to a concrete subclass. However, this doesn't seem to work in all cases: Given class Base(ABC): @abstractmet...
Open Graph Description: #1843/#2853 added support for instantiating variables with an abstract type, under the assumption that it will always be applied to a concrete subclass. However, this doesn't seem to work in all ca...
X Description: #1843/#2853 added support for instantiating variables with an abstract type, under the assumption that it will always be applied to a concrete subclass. However, this doesn't seem to work in al...
Opengraph URL: https://github.com/python/mypy/issues/6586
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Instantiating concrete classes fails check in some cases","articleBody":"#1843/#2853 added support for instantiating variables with an abstract type, under the assumption that it will always be applied to a concrete subclass. However, this doesn't seem to work in all cases:\r\n\r\nGiven\r\n```python\r\nclass Base(ABC):\r\n @abstractmethod\r\n def m(self) -> None:\r\n pass\r\n\r\nclass A(Base):\r\n def m(self) -> None:\r\n pass\r\n\r\nclass B(Base):\r\n def m(self) -> None:\r\n pass\r\n```\r\nThen\r\n```python\r\nvar: Type[Base]\r\nif \"foo\" == \"bar\":\r\n var = A\r\nelif \"foo\" == \"baz\":\r\n var = B\r\nelse:\r\n raise RuntimeError()\r\n\r\nvar() # error: Cannot instantiate abstract class 'Base' with abstract attribute 'm'\r\n```\r\n\r\nAs far as I understand it the last line shouldn't result in an error.\r\n\r\nIf I remove class `B` (and the corresponding `elif`) I don't get an error. Interestingly, if I remove the whole `if` block I also don't get an error.\r\n\r\nThis is with version 0.670.","author":{"url":"https://github.com/janlarres","@type":"Person","name":"janlarres"},"datePublished":"2019-03-24T23:44:46Z","url":"https://github.com/python/mypy/issues/6586"}
| 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:979a18a9-f4a2-a39b-133a-f3ac348c77a8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFEA:1DA29F:76C440:9A0EE2:6AFFCDB3 |
| html-safe-nonce | 201b6fb619b113d909efce501b9a6d5864b32843a9cf616f553b648fb0cc3dd0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkVBOjFEQTI5Rjo3NkM0NDA6OUEwRUUyOjZBRkZDREIzIiwidmlzaXRvcl9pZCI6IjU1MTE4NTYxMDM5ODM0MDI0MTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c9f1597a3d40458b411c5435c81b7fbc2c800e7b7a15a9470b797e17d3d50592 |
| hovercard-subject-tag | issue:424675614 |
| 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/6586/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1d663ef092f2172b4a74eff4fb448821d13cdc69c9b63922b03caaf9260d2e42/python/mypy/issues/6586 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1d663ef092f2172b4a74eff4fb448821d13cdc69c9b63922b03caaf9260d2e42/python/mypy/issues/6586 |
| og:image:alt | #1843/#2853 added support for instantiating variables with an abstract type, under the assumption that it will always be applied to a concrete subclass. However, this doesn't seem to work in all ca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | janlarres |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width