Title: Using Generic and __new__ in class def, mypy misses incorrect parameter if parameter created inline · Issue #14009 · python/mypy · GitHub
Open Graph Title: Using Generic and __new__ in class def, mypy misses incorrect parameter if parameter created inline · Issue #14009 · python/mypy
X Title: Using Generic and __new__ in class def, mypy misses incorrect parameter if parameter created inline · Issue #14009 · python/mypy
Description: Bug Report This came up in pandas-stubs, issue pandas-dev/pandas-stubs#412 If you have a stub that defines a Generic class with __new__(), with overloads, and the final overload doesn't specify the type of the generic, then a function ca...
Open Graph Description: Bug Report This came up in pandas-stubs, issue pandas-dev/pandas-stubs#412 If you have a stub that defines a Generic class with __new__(), with overloads, and the final overload doesn't specify the...
X Description: Bug Report This came up in pandas-stubs, issue pandas-dev/pandas-stubs#412 If you have a stub that defines a Generic class with __new__(), with overloads, and the final overload doesn't specify...
Opengraph URL: https://github.com/python/mypy/issues/14009
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using Generic and __new__ in class def, mypy misses incorrect parameter if parameter created inline","articleBody":"\r\n**Bug Report**\r\n\r\nThis came up in pandas-stubs, issue https://github.com/pandas-dev/pandas-stubs/issues/412\r\n\r\nIf you have a stub that defines a `Generic` class with `__new__()`, with overloads, and the final overload doesn't specify the type of the generic, then a function call that creates an object of the generic class in the function call is not picked up as an error, but it is picked up if stored in another variable.\r\n\r\n**To Reproduce**\r\n\r\nTwo files are needed. First is `gptst2.pyi` :\r\n```python\r\nfrom typing import Generic, TypeVar, Type, overload\r\n\r\nTV = TypeVar(\"TV\", int, str)\r\n\r\nclass Foo(Generic[TV]):\r\n @overload\r\n def __new__(cls, ty: Type[TV]) -> Foo[TV]: ...\r\n @overload\r\n def __new__(cls, ty=...) -> Foo: ...\r\n```\r\nThen the tester code `genparam.py`:\r\n```python\r\nfrom gptst2 import Foo\r\n\r\n\r\ndef fun(param: Foo[int]) -> Foo[str]:\r\n ...\r\n\r\n\r\nfun(param=Foo(str))\r\np = Foo(str)\r\nfun(p)\r\n```\r\n\r\n\r\n**Expected Behavior**\r\n\r\nmypy should report errors on both calls to `fun()`\r\n\r\n**Actual Behavior**\r\nmypy does not pick up that the first call to `fun` is incorrect. It does pick up that the second call is incorrect.\r\npyright picks up both as being incorrect.\r\n\r\nOutput from mypy:\r\n```text\r\ngenparam.py:10: error: Argument 1 to \"fun\" has incompatible type \"Foo[str]\"; expected \"Foo[int]\"\r\n```\r\n\r\n**Your Environment**\r\n\r\n\r\n- Mypy version used: 0.971\r\n- Mypy command-line flags: `--no-incremental`\r\n- Mypy configuration options from `mypy.ini` (and other config files): None\r\n- Python version used: 3.10\r\n\r\n\r\n","author":{"url":"https://github.com/Dr-Irv","@type":"Person","name":"Dr-Irv"},"datePublished":"2022-11-04T17:04:02Z","url":"https://github.com/python/mypy/issues/14009"}
| 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:54df0a82-411d-fcf0-d203-7912a7e4e099 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CBD0:30263F:233D8AB:2FF8054:6B002EA6 |
| html-safe-nonce | 1d04ad802b59b7f392f0db5964555db30beffbe53880f7f1ce0e2689dbe9091c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkQwOjMwMjYzRjoyMzNEOEFCOjJGRjgwNTQ6NkIwMDJFQTYiLCJ2aXNpdG9yX2lkIjoiNzA5NTk4MDA5NzMzNjc4MjUwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9cce9362e68fc1c981e7ae6eb04b155c08ae376ad696e9f2350a88a8140acd8e |
| hovercard-subject-tag | issue:1436384777 |
| 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/14009/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b42f158e1a1f0843b25542c027b37a8a19c1015b080c342e24a7d7bf625ae76a/python/mypy/issues/14009 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b42f158e1a1f0843b25542c027b37a8a19c1015b080c342e24a7d7bf625ae76a/python/mypy/issues/14009 |
| og:image:alt | Bug Report This came up in pandas-stubs, issue pandas-dev/pandas-stubs#412 If you have a stub that defines a Generic class with __new__(), with overloads, and the final overload doesn't specify the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Dr-Irv |
| 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