Title: Too many arguments / Invalid self argument when referencing callable attribute of an object. · Issue #9975 · python/mypy · GitHub
Open Graph Title: Too many arguments / Invalid self argument when referencing callable attribute of an object. · Issue #9975 · python/mypy
X Title: Too many arguments / Invalid self argument when referencing callable attribute of an object. · Issue #9975 · python/mypy
Description: Bug Report To Reproduce This code: import dataclasses as dc from enum import Enum from typing import cast, Any, Callable, Dict, List class ScalingDirection(Enum): SCALE_UP = 'up' SCALE_DOWN = 'down' @dc.dataclass class InstanceScalingSta...
Open Graph Description: Bug Report To Reproduce This code: import dataclasses as dc from enum import Enum from typing import cast, Any, Callable, Dict, List class ScalingDirection(Enum): SCALE_UP = 'up' SCALE_DOWN = 'down...
X Description: Bug Report To Reproduce This code: import dataclasses as dc from enum import Enum from typing import cast, Any, Callable, Dict, List class ScalingDirection(Enum): SCALE_UP = 'up' SCALE_DOWN...
Opengraph URL: https://github.com/python/mypy/issues/9975
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Too many arguments / Invalid self argument when referencing callable attribute of an object.","articleBody":"**Bug Report**\r\n\r\n**To Reproduce**\r\n\r\nThis code:\r\n```python\r\nimport dataclasses as dc\r\nfrom enum import Enum\r\nfrom typing import cast, Any, Callable, Dict, List\r\n\r\n\r\nclass ScalingDirection(Enum):\r\n SCALE_UP = 'up'\r\n SCALE_DOWN = 'down'\r\n\r\n\r\n@dc.dataclass\r\nclass InstanceScalingStatus:\r\n label: str\r\n scaling_check: Callable[[ScalingDirection], bool]\r\n is_scaling_finished: bool = False\r\n\r\n\r\ndef _check_scaling_states(scaling_states: Dict[str, InstanceScalingStatus],\r\n scaling_direction: ScalingDirection) -> bool:\r\n \r\n for name, scaling_state in scaling_states.items():\r\n if scaling_state.scaling_check(scaling_direction):\r\n scaling_state.is_scaling_finished = True\r\n\r\n not_yet_scaled: List[str] = [state.label for state in scaling_states.values() if not state.is_scaling_finished]\r\n if len(not_yet_scaled) > 0:\r\n return False\r\n\r\n return True \r\n```\r\n\r\n**Expected Behavior**\r\n\r\nThe `scaling_state.scaling_check(scaling_direction)` is not a function call on an object. There's no `self` and the Callable clearly states it only takes a single argument. It's a de-reference of a attribute that points to a callable, and call to that callable. It works, no other linter we use complains about this syntax. I belive `mypy` shouldn't either.\r\n\r\n**Actual Behavior**\r\n\r\nFails with:\r\n```bash\r\n→ mypy --version\r\nmypy 0.800\r\n→ mypy test2.py\r\ntest2.py:22: error: Invalid self argument \"InstanceScalingStatus\" to attribute function \"scaling_check\" with type \"Callable[[ScalingDirection], bool]\"\r\ntest2.py:22: error: Too many arguments\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: `0.800`\r\n- Mypy command-line flags: `None`\r\n- Mypy configuration options from `mypy.ini` (and other config files): `None`\r\n- Python version used: `3.8.3`\r\n- Operating system and version: `Windows 10 / WSL 1 / FedoraRemix 31`\r\n","author":{"url":"https://github.com/mkielar","@type":"Person","name":"mkielar"},"datePublished":"2021-01-26T17:40:08Z","url":"https://github.com/python/mypy/issues/9975"}
| 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:914ed3f4-01a1-dcfc-1227-51d0759a84c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A6C:3FDF0C:2373F1:2F5759:6B00229F |
| html-safe-nonce | 4ba33fb1649f72cf6977d81a153af463aefec34a3be452b906c84dd4962f79e5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QTZDOjNGREYwQzoyMzczRjE6MkY1NzU5OjZCMDAyMjlGIiwidmlzaXRvcl9pZCI6Ijg2Mjk3NTUzMDU3NzA2MjM2NDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7e78fc00138b958c6d5e111fb1efab39a1f540fbc3bc835491fd8d5e86b1582b |
| hovercard-subject-tag | issue:794428767 |
| 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/9975/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3719a3bed75f983a5653d465b88b327b64b9deb644b2d8a2ea96910d8a2ef22b/python/mypy/issues/9975 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3719a3bed75f983a5653d465b88b327b64b9deb644b2d8a2ea96910d8a2ef22b/python/mypy/issues/9975 |
| og:image:alt | Bug Report To Reproduce This code: import dataclasses as dc from enum import Enum from typing import cast, Any, Callable, Dict, List class ScalingDirection(Enum): SCALE_UP = 'up' SCALE_DOWN = 'down... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mkielar |
| 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