Title: Incorrect overalp detected in __rmod__ with str argument · Issue #7402 · python/mypy · GitHub
Open Graph Title: Incorrect overalp detected in __rmod__ with str argument · Issue #7402 · python/mypy
X Title: Incorrect overalp detected in __rmod__ with str argument · Issue #7402 · python/mypy
Description: Problem observed using current HEAD (0.730+dev.d2a7f05d27d9ac5c096c61ecf0455edda91f5d5a) but can confirmed on 0.660 as well, so it is nothing new. Flags used: --python-version 3.7 --strict-optional --no-site-packages --show-traceback --n...
Open Graph Description: Problem observed using current HEAD (0.730+dev.d2a7f05d27d9ac5c096c61ecf0455edda91f5d5a) but can confirmed on 0.660 as well, so it is nothing new. Flags used: --python-version 3.7 --strict-optional...
X Description: Problem observed using current HEAD (0.730+dev.d2a7f05d27d9ac5c096c61ecf0455edda91f5d5a) but can confirmed on 0.660 as well, so it is nothing new. Flags used: --python-version 3.7 --strict-optional...
Opengraph URL: https://github.com/python/mypy/issues/7402
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect overalp detected in __rmod__ with str argument","articleBody":"Problem observed using current HEAD (0.730+dev.d2a7f05d27d9ac5c096c61ecf0455edda91f5d5a) but can confirmed on 0.660 as well, so it is nothing new.\r\n\r\nFlags used:\r\n\r\n- `--python-version 3.7 --strict-optional --no-site-packages --show-traceback --no-implicit-optional`\r\n- Also confirmed with no flags at all (Python 3.7)\r\n\r\nProblem occurs:\r\n\r\n- With `__mod__` / `__rmod__` pair.\r\n- When other in `__mod__` is `Union[T, str]`, where `T` can be self type, or some other type (let's say `int`).\r\n- When other in `__rmod__` is `str`.\r\n- When return type annotation for `__rmod__` is provided,\r\n\r\n\r\nReproducible example:\r\n\r\n```python\r\nfrom typing import Union\r\n\r\nclass Foo:\r\n def __mod__(self, other: Union[Foo, str]) -> Foo: ...\r\n def __rmod__(self, other: str) -> Foo: ...\r\n```\r\n\r\nyields\r\n\r\n```\r\nfoo.py:5: error: Signatures of \"__rmod__\" of \"Foo\" and \"__mod__\" of \"str\" are unsafely overlapping\r\n```\r\n\r\nIssue is specific to `__mod__` / `__rmod__` pair, i.e. this works just fine:\r\n\r\n```python\r\nfrom typing import Union\r\n\r\nclass Foo:\r\n def __mul__(self, other: Union[Foo, str]) -> Foo: ...\r\n def __rmul__(self, other: str) -> Foo: ...\r\n```\r\n\r\nand I haven't found any other problematic pair.\r\n\r\nAs far as I can tell it strictly depends on `other` being `str`. For example this works just fine\r\n\r\n```python\r\nfrom typing import Union\r\n\r\nclass Foo:\r\n def __mod__(self, other: Union[Foo, int]) -> Foo: ...\r\n def __rmod__(self, other: int) -> Foo: ...\r\n```\r\n\r\nAdditionally, to reproduce the problem, we need a return type annotation on `__rmod__`, and removing it is sufficient to pass type check (removing return type annotation from `__mod__` has no impact at all):\r\n\r\n```python\r\nfrom typing import Union\r\n \r\nclass Foo:\r\n def __mod__(self, other: Union[Foo, str]) -> Foo: ... \r\n def __rmod__(self, other: str): ... \r\n```\r\n\r\nthough failure is not specifically caused by referencing self type, as for example this, will fail as well\r\n\r\n```python\r\nfrom typing import Union\r\n \r\nclass Foo:\r\n def __mod__(self, other: Union[Foo, str]) -> int: ... \r\n def __rmod__(self, other: str) -> int: ... \r\n```\r\n\r\n```\r\nfoo.py:5: error: Signatures of \"__rmod__\" of \"Foo\" and \"__mod__\" of \"str\" are unsafely overlapping\r\n```\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/zero323","@type":"Person","name":"zero323"},"datePublished":"2019-08-28T19:10:12Z","url":"https://github.com/python/mypy/issues/7402"}
| 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:72f69d9c-0936-d5d6-33a2-6e5f4d651066 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 982A:2C0A92:2E6A4B0:3D22F0B:6B00200F |
| html-safe-nonce | 098fc799e5832b76d3ba4649c8c2730ca1a8241b9138c7748d183cba7ee022bd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODJBOjJDMEE5MjoyRTZBNEIwOjNEMjJGMEI6NkIwMDIwMEYiLCJ2aXNpdG9yX2lkIjoiMjMzNzY1ODEwNTgwODAzNTg1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7a427ea0c96399d8ea8a7ee4b7c6069c77921280f5751b6cc9fd20a475d3a9cd |
| hovercard-subject-tag | issue:486559114 |
| 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/7402/issue_layout |
| twitter:image | https://opengraph.githubassets.com/49b657d6053e2e4cb5612bc843eeea2d5bb689cbfd2a28792abf5204a6a613e2/python/mypy/issues/7402 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/49b657d6053e2e4cb5612bc843eeea2d5bb689cbfd2a28792abf5204a6a613e2/python/mypy/issues/7402 |
| og:image:alt | Problem observed using current HEAD (0.730+dev.d2a7f05d27d9ac5c096c61ecf0455edda91f5d5a) but can confirmed on 0.660 as well, so it is nothing new. Flags used: --python-version 3.7 --strict-optional... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zero323 |
| 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