Title: Spurious "Invalid self argument ... to attribute function" error when currying TypeVarTuple · Issue #17184 · python/mypy · GitHub
Open Graph Title: Spurious "Invalid self argument ... to attribute function" error when currying TypeVarTuple · Issue #17184 · python/mypy
X Title: Spurious "Invalid self argument ... to attribute function" error when currying TypeVarTuple · Issue #17184 · python/mypy
Description: Bug Report I'm getting an "Invalid self argument ... to attribute function" error when inheriting and simultaneously augmenting the TypeVarTuple. The error happens only when calling attribute functions, and not when accessing normal attr...
Open Graph Description: Bug Report I'm getting an "Invalid self argument ... to attribute function" error when inheriting and simultaneously augmenting the TypeVarTuple. The error happens only when calling attribute funct...
X Description: Bug Report I'm getting an "Invalid self argument ... to attribute function" error when inheriting and simultaneously augmenting the TypeVarTuple. The error happens only when calling a...
Opengraph URL: https://github.com/python/mypy/issues/17184
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Spurious \"Invalid self argument ... to attribute function\" error when currying TypeVarTuple","articleBody":"**Bug Report**\r\n\r\nI'm getting an \"Invalid self argument ... to attribute function\" error when inheriting and simultaneously augmenting the TypeVarTuple. The error happens only when calling attribute functions, and not when accessing normal attributes.\r\n\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom typing import Iterator, TypeGuard, TypeVar, Iterable, Type, Any, Callable, TypeVarTuple, Generic\r\n\r\n\r\nT = TypeVarTuple('T')\r\n\r\n\r\nclass Base(Generic[*T]):\r\n\r\n attr: tuple[*T]\r\n \r\n @property\r\n def prop(self) -> tuple[*T]:\r\n return self.attr\r\n\r\n def meth(self) -> tuple[*T]:\r\n return self.attr\r\n\r\n\r\nS = TypeVarTuple('S')\r\n\r\n\r\nclass Derived(Base[str, *S]):\r\n \r\n def frob(self) -> None:\r\n reveal_type(self.attr) # OK: \"tuple[builtins.str, Unpack[S`1]]\"\r\n reveal_type(self.prop) # Error\r\n reveal_type(self.meth()) # Error\r\n\r\n\r\nd: Derived[int]\r\nreveal_type(d.attr) # OK: tuple[str, int]\r\nreveal_type(d.prop) # OK: tuple[str, int]\r\nreveal_type(d.meth()) # OK: tuple[str, int]\r\n```\r\n\r\nGist URL: https://gist.github.com/mypy-play/531a3a730ac2b172120e2fa1a2c307b8\r\nPlayground URL: https://mypy-play.net/?mypy=latest&python=3.12&gist=531a3a730ac2b172120e2fa1a2c307b8\r\n\r\n**Expected Behavior**\r\n\r\nIn the derived class, accessing base attributes (`self.attr`), base properties (`self.prop`), and base methods (`self.meth()`) should work.\r\n\r\n**Actual Behavior**\r\n\r\nAccessing the base properties (`self.prop`), and base methods (`self.meth()`) causes a spurious \r\n```\r\nerror: Invalid self argument \"Derived[*S]\" to attribute function \"prop\" with type \"Callable[[Base[*T]], tuple[*T]]\" [misc]\r\n```\r\nAt the same time, `reveal_type` reports the expected type despite the error.\r\n\r\nFull mypy output:\r\n```\r\nmain.py:23: note: Revealed type is \"tuple[builtins.bytes, Unpack[S`1]]\"\r\nmain.py:24: error: Invalid self argument \"Derived[*S]\" to attribute function \"prop\" with type \"Callable[[Base[*T]], tuple[*T]]\" [misc]\r\nmain.py:24: note: Revealed type is \"tuple[builtins.bytes, Unpack[S`1]]\"\r\nmain.py:25: error: Invalid self argument \"Derived[*S]\" to attribute function \"meth\" with type \"Callable[[Base[*T]], tuple[*T]]\" [misc]\r\nmain.py:25: note: Revealed type is \"tuple[builtins.bytes, Unpack[S`1]]\"\r\nmain.py:29: note: Revealed type is \"tuple[builtins.bytes, builtins.str, builtins.float]\"\r\nmain.py:30: note: Revealed type is \"tuple[builtins.bytes, builtins.str, builtins.float]\"\r\nmain.py:31: note: Revealed type is \"tuple[builtins.bytes, builtins.str, builtins.float]\"\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 1.10.0, also earlier versions\r\n- Mypy command-line flags: none (also happens with `--strict`)\r\n- Mypy configuration options from `mypy.ini` (and other config files): None\r\n- Python version used: Tested on 3.11 and 3.12\r\n\r\n","author":{"url":"https://github.com/vbraun","@type":"Person","name":"vbraun"},"datePublished":"2024-04-27T16:07:19Z","url":"https://github.com/python/mypy/issues/17184"}
| 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:677173e0-792a-3b59-6731-493307249bff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 887C:5875E:24C2BE9:32072BD:6B003456 |
| html-safe-nonce | 4e9d5981ecfb8d7ffc23f3ce35ac3d4a0f4d9b1b6e66c9dfc68f5daaf52a3e6b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODdDOjU4NzVFOjI0QzJCRTk6MzIwNzJCRDo2QjAwMzQ1NiIsInZpc2l0b3JfaWQiOiI3ODczOTQyNDQ4NjcyNjE3NTU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3cedfc8f3975cb551ff8d5154de5554099b42cf81f0828473df85c5e0cd79303 |
| hovercard-subject-tag | issue:2267076083 |
| 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/17184/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af2099f724e75f36dcf9b8ffb63cd71ae94dfe4d6bdec97226e29fdfe0b18492/python/mypy/issues/17184 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af2099f724e75f36dcf9b8ffb63cd71ae94dfe4d6bdec97226e29fdfe0b18492/python/mypy/issues/17184 |
| og:image:alt | Bug Report I'm getting an "Invalid self argument ... to attribute function" error when inheriting and simultaneously augmenting the TypeVarTuple. The error happens only when calling attribute funct... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vbraun |
| 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