Title: Adding @abstractmethod __init__ to ABC breaks staticmethods · Issue #1706 · python/mypy · GitHub
Open Graph Title: Adding @abstractmethod __init__ to ABC breaks staticmethods · Issue #1706 · python/mypy
X Title: Adding @abstractmethod __init__ to ABC breaks staticmethods · Issue #1706 · python/mypy
Description: I was trying to create an ABC that also worked as a factory. from abc import ( ABCMeta, abstractmethod, ) class WidgetWithInit(object): __metaclass__ = ABCMeta @abstractmethod def __init__(self, foo, bar): # type: (int, int) -> None pass...
Open Graph Description: I was trying to create an ABC that also worked as a factory. from abc import ( ABCMeta, abstractmethod, ) class WidgetWithInit(object): __metaclass__ = ABCMeta @abstractmethod def __init__(self, fo...
X Description: I was trying to create an ABC that also worked as a factory. from abc import ( ABCMeta, abstractmethod, ) class WidgetWithInit(object): __metaclass__ = ABCMeta @abstractmethod def __init__(self, fo...
Opengraph URL: https://github.com/python/mypy/issues/1706
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Adding @abstractmethod __init__ to ABC breaks staticmethods","articleBody":"I was trying to create an ABC that also worked as a factory.\n\n```\nfrom abc import (\n ABCMeta,\n abstractmethod,\n)\n\nclass WidgetWithInit(object):\n __metaclass__ = ABCMeta\n\n @abstractmethod\n def __init__(self, foo, bar):\n # type: (int, int) -> None\n pass\n\n @staticmethod\n def add(foo, bar):\n # type: (int, int) -> int\n return foo + bar\n\n @classmethod\n def add_class(cls, foo, bar):\n # type: (int, int) -> int\n return foo + bar\n\nWidgetWithInit.add(1, '2')\nWidgetWithInit.add_class(1, '2')\n\nclass WidgetNoInit(object):\n __metaclass__ = ABCMeta\n\n @staticmethod\n def add(foo, bar):\n # type: (int, int) -> int\n return foo + bar\n\n @classmethod\n def add_class(cls, foo, bar):\n # type: (int, int) -> int\n return foo + bar\n\nWidgetNoInit.add(1, '2')\nWidgetNoInit.add_class(1, '2')\n```\n\nMyPy will respond:\n\n```\nrt6.py:40: error: Argument 2 to \"add\" of \"WidgetNoInit\" has incompatible type \"str\"; expected \"int\"\nrt6.py:41: error: Argument 2 to \"add_class\" of \"WidgetNoInit\" has incompatible type \"str\"; expected \"int\"\n```\n\nSo adding the `def __init__` seems to make the staticmethod and classmethod have a type of Any.\n\nFortunately I can work around it by not defining **init** in the ABC, and having my `def create` enforce the signature.\n","author":{"url":"https://github.com/euresti","@type":"Person","name":"euresti"},"datePublished":"2016-06-14T14:06:31Z","url":"https://github.com/python/mypy/issues/1706"}
| 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:748617c2-eb0c-2487-1f7c-25dd55dbf4e6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9C86:1DA29F:C49E3C:FFAFD7:6AFFE53B |
| html-safe-nonce | 140342dfd073517c61763301e8fe128db66c8d2d62761970e155f2ea5779639a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Qzg2OjFEQTI5RjpDNDlFM0M6RkZBRkQ3OjZBRkZFNTNCIiwidmlzaXRvcl9pZCI6IjM1NjEzNDQ2MzQwNDUwNjQ1MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9c2e00d3e6a2e8d232b70b7fc8afc57c33a4d4df1e6d363c757ce66eaa3c89d7 |
| hovercard-subject-tag | issue:160190303 |
| 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/1706/issue_layout |
| twitter:image | https://opengraph.githubassets.com/17426449e1d465ea52b8329f642de4e89e1996413f287d1c6bf643893eae7065/python/mypy/issues/1706 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/17426449e1d465ea52b8329f642de4e89e1996413f287d1c6bf643893eae7065/python/mypy/issues/1706 |
| og:image:alt | I was trying to create an ABC that also worked as a factory. from abc import ( ABCMeta, abstractmethod, ) class WidgetWithInit(object): __metaclass__ = ABCMeta @abstractmethod def __init__(self, fo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | euresti |
| 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