Title: Mypy doesn't catch renaming arguments in overrides · Issue #19132 · python/mypy · GitHub
Open Graph Title: Mypy doesn't catch renaming arguments in overrides · Issue #19132 · python/mypy
X Title: Mypy doesn't catch renaming arguments in overrides · Issue #19132 · python/mypy
Description: Bug Report When overriding methods in subclasses, it's important to keep the same argument names since any argument in Python can be given as a keyword argument. If an override in a subclass changes the name of a parameter, it breaks the...
Open Graph Description: Bug Report When overriding methods in subclasses, it's important to keep the same argument names since any argument in Python can be given as a keyword argument. If an override in a subclass change...
X Description: Bug Report When overriding methods in subclasses, it's important to keep the same argument names since any argument in Python can be given as a keyword argument. If an override in a subclass ch...
Opengraph URL: https://github.com/python/mypy/issues/19132
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy doesn't catch renaming arguments in overrides","articleBody":"**Bug Report**\n\nWhen overriding methods in subclasses, it's important to keep the same argument names since any argument in Python can be given as a keyword argument. If an override in a subclass changes the name of a parameter, it breaks the polymorphism for any user of the class using keyword arguments\n\n**To Reproduce**\n\n```python\nfrom abc import ABC, abstractmethod\n\n\nclass Adder(ABC):\n @abstractmethod\n def add(self, a: int, b: int) -> int:\n pass\n\n\nclass MyAdder(Adder):\n def add(self, a: int, b: int) -> int:\n return a + b\n\n\nclass OtherAdder(Adder):\n def add(self, a: int, new_b: int) -> int:\n return a + new_b\n\n\ndef use_adder(adder: Adder) -> int:\n return adder.add(a=1, b=2)\n\n\nprint(f\"1 + 2 = {use_adder(MyAdder())}\") # works\nprint(f\"1 + 2 = {use_adder(OtherAdder())}\") # broken, but type checks in mypy\n```\n\n**Expected Behavior**\n\nThe code example above should not type check, as `OtherAdder` is not a valid subclass of `Adder`. If I type check this code in `pyright`, it correctly identifies this issue:\n\n``` commandline\n$ pyright classes.py\n/path/to/classes.py\n /path/to/classes.py:16:9 - error: Method \"add\" overrides class \"Adder\" in an incompatible manner\n Parameter 3 name mismatch: base parameter is named \"b\", override parameter is named \"new_b\" (reportIncompatibleMethodOverride)\n1 error, 0 warnings, 0 informations\n```\n\n**Actual Behavior**\n\nMypy lets this error through:\n\n``` commandline\n$ mypy classes.py\nSuccess: no issues found in 1 source file\n```\n\n**Your Environment**\n\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\n\n- Mypy version used: `mypy 1.15.0 (compiled: yes)`\n- Mypy command-line flags: None\n- Mypy configuration options from `mypy.ini` (and other config files): None\n- Python version used: `Python 3.13.3`\n\n\u003c!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->\n","author":{"url":"https://github.com/mathialo","@type":"Person","name":"mathialo"},"datePublished":"2025-05-22T12:49:09Z","url":"https://github.com/python/mypy/issues/19132"}
| 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:9aea6651-086e-03fd-5599-597c047b8b45 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EBEE:22FAD4:3EB10C:540AB5:6B002A94 |
| html-safe-nonce | 8cd44b243cbd1af343de26aad88d7b5aacbceb5056d456b68fd828bcf53fd45d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkVFOjIyRkFENDozRUIxMEM6NTQwQUI1OjZCMDAyQTk0IiwidmlzaXRvcl9pZCI6IjUyNzkyODgzNzk0MzM4MjI4NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 932df3b09083d67962466aaba3e9d98672a1109971e7fa26d69c89415be9a5d8 |
| hovercard-subject-tag | issue:3083271471 |
| 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/19132/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ebbdb2513003c722886752b28d0b37adc4caa73f0013ee76f42822aa78fc7318/python/mypy/issues/19132 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ebbdb2513003c722886752b28d0b37adc4caa73f0013ee76f42822aa78fc7318/python/mypy/issues/19132 |
| og:image:alt | Bug Report When overriding methods in subclasses, it's important to keep the same argument names since any argument in Python can be given as a keyword argument. If an override in a subclass change... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mathialo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width