Title: Mypyc ignores custom `__new__` without warning · Issue #16012 · python/mypy · GitHub
Open Graph Title: Mypyc ignores custom `__new__` without warning · Issue #16012 · python/mypy
X Title: Mypyc ignores custom `__new__` without warning · Issue #16012 · python/mypy
Description: Mypyc apprently ignores custom __new__ methods without warning. It would be great if it could abide by the custom __new__, but otherwise a warning / error should be raised. Example code (see #1020 (comment)): from __future__ import annot...
Open Graph Description: Mypyc apprently ignores custom __new__ methods without warning. It would be great if it could abide by the custom __new__, but otherwise a warning / error should be raised. Example code (see #1020 ...
X Description: Mypyc apprently ignores custom __new__ methods without warning. It would be great if it could abide by the custom __new__, but otherwise a warning / error should be raised. Example code (see #1020 ...
Opengraph URL: https://github.com/python/mypy/issues/16012
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypyc ignores custom `__new__` without warning","articleBody":"Mypyc apprently ignores custom `__new__` methods without warning. It would be great if it could abide by the custom `__new__`, but otherwise a warning / error should be raised.\r\n\r\nExample code (see https://github.com/python/mypy/issues/1020#issuecomment-1703221367):\r\n\r\n```python\r\nfrom __future__ import annotations\r\n\r\nclass Add:\r\n l: IntLike\r\n r: IntLike\r\n\r\n def __new__(cls, l: IntLike, r: IntLike) -> IntLike: # type: ignore[misc]\r\n print(f'running __new__ with {l} and {r}')\r\n\r\n return (\r\n l if r == 0 else\r\n r if l == 0 else\r\n super().__new__(cls)\r\n )\r\n\r\n def __init__(self, l: IntLike, r: IntLike):\r\n self.l = l\r\n self.r = r\r\n\r\n def __repr__(self) -> str:\r\n return f'({self.l} + {self.r})'\r\n\r\n def __add__(self, other: IntLike) -> IntLike:\r\n return Add(self, other)\r\n\r\nIntLike = int | Add\r\n```\r\n\r\nCode for running:\r\n\r\n```python\r\nprint(f'{Add(1, 5)=}')\r\nprint(f'{Add(0, 5)=}')\r\nprint(f'{Add(1, 0)=}')\r\n```\r\n\r\nRunning this interpreted gives:\r\n\r\n```\r\nrunning __new__ with 1 and 5\r\nAdd(1, 5)=(1 + 5)\r\nrunning __new__ with 0 and 5\r\nAdd(0, 5)=5\r\nrunning __new__ with 1 and 0\r\nAdd(1, 0)=1\r\n```\r\n\r\nRunning compiled:\r\n\r\n```\r\nAdd(1, 5)=(1 + 5)\r\nAdd(0, 5)=(0 + 5)\r\nAdd(1, 0)=(1 + 0)\r\n```\r\n\r\nThe interpreted and compiled behaviors are different, which is bad.","author":{"url":"https://github.com/nickdrozd","@type":"Person","name":"nickdrozd"},"datePublished":"2023-09-01T19:28:39Z","url":"https://github.com/python/mypy/issues/16012"}
| 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:32a7f259-8f92-d8ab-c80f-730f0d31b082 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 864E:5875E:21FF17F:2E36596:6B002571 |
| html-safe-nonce | 37a92faab50541ae65fcc2bddeb57b29a97569d701d3e52eb7cef20a7932b757 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjRFOjU4NzVFOjIxRkYxN0Y6MkUzNjU5Njo2QjAwMjU3MSIsInZpc2l0b3JfaWQiOiIzNzY1NDcxMzU1NzQzNTExOTIxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3dae15aa7c048d442ff0018ca2a29707a461043b640d1274bbef7ce227e9cb86 |
| hovercard-subject-tag | issue:1877952112 |
| 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/16012/issue_layout |
| twitter:image | https://opengraph.githubassets.com/945ded76541a13027f6bc1216af50afc35ebd36dd47f8b81260f1eb846ac40e8/python/mypy/issues/16012 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/945ded76541a13027f6bc1216af50afc35ebd36dd47f8b81260f1eb846ac40e8/python/mypy/issues/16012 |
| og:image:alt | Mypyc apprently ignores custom __new__ methods without warning. It would be great if it could abide by the custom __new__, but otherwise a warning / error should be raised. Example code (see #1020 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nickdrozd |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width