Title: Subclass method parameter names are not checked against superclass · Issue #6709 · python/mypy · GitHub
Open Graph Title: Subclass method parameter names are not checked against superclass · Issue #6709 · python/mypy
X Title: Subclass method parameter names are not checked against superclass · Issue #6709 · python/mypy
Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to simplify your case to a minimal repro. Whe...
Open Graph Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to si...
X Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to si...
Opengraph URL: https://github.com/python/mypy/issues/6709
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Subclass method parameter names are not checked against superclass","articleBody":"* Are you reporting a bug, or opening a feature request?\r\n\r\nBug\r\n\r\n* Please insert below the code you are checking with mypy,\r\n or a mock-up repro if the source is private. We would appreciate\r\n if you try to simplify your case to a minimal repro.\r\n\r\nWhen a subclass renames the parameters of a method, this results in runtime errors; but this seems like something that should be statically detectable.\r\n\r\nThe below code provides a superclass `A`, and two similar subclasses `B` and `C` that differ in that `C` renames the parameter to the method `f`, but `B` does not.\r\n\r\nmypy vs runtime behaviour for variables `c` and `c2` seems inconsistent, while for `c3` and `c4` it seems ok.\r\n\r\nI was expecting some mypy error to be raised when defining `f` in class `C`.\r\n\r\n```\r\nclass A:\r\n def f(self, x: int) -> None:\r\n print(\"A: \", x)\r\n\r\nclass B(A):\r\n def f(self, x: int) -> None:\r\n print(\"B: \", x)\r\n\r\nclass C(A):\r\n def f(self, n: int) -> None:\r\n print(\"C: \", n)\r\n\r\na = A()\r\na.f(x=3)\r\n\r\nb = B() # type: A\r\nb.f(x=3)\r\n\r\nc = C() # type: A\r\nc.f(x=3) # mypy passes, but gives runtime error: TypeError: f() got an unexpected keyword argument 'x'\r\n\r\nc2 = C() # type: A\r\nc2.f(n=3) # mypy gives an error: error: Unexpected keyword argument \"n\" for \"f\" of \"A\" but runtime works.\r\n\r\nc3 = C() # type: C\r\nc3.f(x=3) # mypy give type error: error: Unexpected keyword argument \"x\" for \"f\" of \"C\", and runtime error: mypy-issue.py:25: error: Unexpected keyword argument \"x\" for \"f\" of \"C\"\r\n\r\nc4 = C() # type: C\r\nc4.f(n=3) # no errors in mypy or at runtime\r\n```\r\n\r\n* What are the versions of mypy and Python you are using?\r\n\r\n$ mypy --version\r\nmypy 0.670\r\n$ python --version\r\nPython 3.7.2+\r\n\r\n* Do you see the same issue after installing mypy from Git master?\r\n\r\nyes - mypy 0.710+dev.f10528a5a8d9e98939ceb84d40e614d1f159d9a0\r\n\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n\r\nWith no flags, and with `--strict`.\r\n","author":{"url":"https://github.com/benclifford","@type":"Person","name":"benclifford"},"datePublished":"2019-04-22T10:38:32Z","url":"https://github.com/python/mypy/issues/6709"}
| 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:894ed5a8-604b-4acd-4f54-ed566247043d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A1EE:7F150:C1B012:FC7B12:6AFFE57B |
| html-safe-nonce | 8fcb682e908c0aaae45bf2ed6a05389b43ad48720c5220323b76e96b9e4b0ee1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUVFOjdGMTUwOkMxQjAxMjpGQzdCMTI6NkFGRkU1N0IiLCJ2aXNpdG9yX2lkIjoiNzc3MTg1MjcyOTYwOTA4NjMzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b037b15c0f696ed9de389ae14e613c0110ce33df0ce1915111ec6437ec5900a6 |
| hovercard-subject-tag | issue:435683525 |
| 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/6709/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6c76533ceb84c3b47938212c2e237975ab5c3c61d02dbbe791fdaa48fd2fa694/python/mypy/issues/6709 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6c76533ceb84c3b47938212c2e237975ab5c3c61d02dbbe791fdaa48fd2fa694/python/mypy/issues/6709 |
| og:image:alt | Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to si... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | benclifford |
| 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