Title: Mypy crash when @staticmethod has the same name as an attr · Issue #6715 · python/mypy · GitHub
Open Graph Title: Mypy crash when @staticmethod has the same name as an attr · Issue #6715 · python/mypy
X Title: Mypy crash when @staticmethod has the same name as an attr · Issue #6715 · python/mypy
Description: Summary of the issue: When using attrs to create a dataclass, adding a static method to the class with the same name as one of the attributes causes mypy to crash. I am happy to work on a fix here, but would need some guidance on where t...
Open Graph Description: Summary of the issue: When using attrs to create a dataclass, adding a static method to the class with the same name as one of the attributes causes mypy to crash. I am happy to work on a fix here,...
X Description: Summary of the issue: When using attrs to create a dataclass, adding a static method to the class with the same name as one of the attributes causes mypy to crash. I am happy to work on a fix here,...
Opengraph URL: https://github.com/python/mypy/issues/6715
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy crash when @staticmethod has the same name as an attr","articleBody":"Summary of the issue:\r\n\r\nWhen using `attrs` to create a dataclass, adding a static method to the class with the same name as one of the attributes causes `mypy` to crash.\r\n\r\nI am happy to work on a fix here, but would need some guidance on where to start.\r\n\r\nPlease provide more information to help us understand the issue:\r\n\r\n* Are you reporting a bug, or opening a feature request?\r\n\r\nThis is a bug - `mypy` should not crash when running against files.\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\nThe following is an minimal reproduction of the issue:\r\n```python\r\nimport attr\r\n\r\n@attr.s\r\nclass MyData:\r\n is_foo: bool = attr.ib()\r\n\r\n @staticmethod\r\n def is_foo(string: str) -> bool:\r\n return False\r\n```\r\n\r\n* What is the actual behavior/output?\r\n\r\nWhen run against the above file, `mypy` crashes with the following error output:\r\n\r\n```bash\r\n$~ mypy test.py --show-traceback\r\ntest.py:5: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.701\r\nTraceback (most recent call last):\r\n File \"/home/james/.local/share/virtualenvs/web-findings-dozQMylR/bin/mypy\", line 10, in \u003cmodule>\r\n sys.exit(console_entry())\r\n File \"mypy/semanal.py\", line 3791, in accept\r\n File \"mypy/nodes.py\", line 895, in accept__Node_glue\r\n File \"mypy/nodes.py\", line 896, in accept\r\n File \"mypy/semanal.py\", line 804, in visit_class_def__StatementVisitor_glue\r\n File \"mypy/semanal.py\", line 807, in visit_class_def\r\n File \"mypy/semanal.py\", line 825, in analyze_class\r\n File \"mypy/semanal.py\", line 833, in analyze_class_body_common\r\n File \"mypy/semanal.py\", line 895, in apply_class_plugin_hooks\r\n File \"mypy/plugins/attrs.py\", line 211, in attr_class_maker_callback\r\n File \"mypy/plugins/attrs.py\", line 267, in _analyze_class\r\nAssertionError:\r\ntest.py:5: : note: use --pdb to drop into pdb\r\n```\r\n\r\n* What is the behavior/output you expect?\r\n\r\nI'm not 100% what I would expect here. I think that `mypy` should probably raise an error about the redefinition of something with the same name, as that is what happens if I change the `staticmethod` to a regular classmethod.\r\n\r\n* What are the versions of mypy and Python you are using?\r\n\r\nPython 3.6.8\r\nmypy 0.701\r\n\r\n* Do you see the same issue after installing mypy from Git master?\r\n\r\nYes, although the traceback is a bit more detailed:\r\n\r\n```bash\r\ntest.py:4: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.710+dev.f0c2506eddf2a06e1d830953541b5d431e50073e\r\ntest.py:4: : note: use --pdb to drop into pdb\r\nTraceback (most recent call last):\r\n File \"/path/to/my/virtualenv/bin/mypy\", line 10, in \u003cmodule>\r\n sys.exit(console_entry())\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/__main__.py\", line 7, in console_entry\r\n main(None)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/main.py\", line 85, in main\r\n res = build.build(sources, options, None, flush_errors, fscache)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/build.py\", line 163, in build\r\n result = _build(sources, options, alt_lib_path, flush_errors, fscache)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/build.py\", line 218, in _build\r\n graph = dispatch(sources, manager)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/build.py\", line 2461, in dispatch\r\n process_graph(graph, manager)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/build.py\", line 2761, in process_graph\r\n process_stale_scc(graph, scc, manager)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/build.py\", line 2862, in process_stale_scc\r\n graph[id].semantic_analysis()\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/build.py\", line 1997, in semantic_analysis\r\n self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/semanal.py\", line 309, in visit_file\r\n self.accept(d)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/semanal.py\", line 3786, in accept\r\n node.accept(self)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/nodes.py\", line 901, in accept\r\n return visitor.visit_class_def(self)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/semanal.py\", line 807, in visit_class_def\r\n self.analyze_class(defn)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/semanal.py\", line 825, in analyze_class\r\n self.analyze_class_body_common(defn)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/semanal.py\", line 833, in analyze_class_body_common\r\n self.apply_class_plugin_hooks(defn)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/semanal.py\", line 895, in apply_class_plugin_hooks\r\n hook(ClassDefContext(defn, decorator, self))\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/plugins/attrs.py\", line 211, in attr_class_maker_callback\r\n attributes = _analyze_class(ctx, auto_attribs, kw_only)\r\n File \"/path/to/my/virtualenv/lib/python3.6/site-packages/mypy/plugins/attrs.py\", line 267, in _analyze_class\r\n assert isinstance(node, Var)\r\nAssertionError: \r\n```\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n\r\nThe local `setup.cfg` file has the following section:\r\n\r\n```ini\r\n[mypy]\r\nignore_missing_imports = True\r\ncheck_untyped_defs = True\r\n```","author":{"url":"https://github.com/leamingrad","@type":"Person","name":"leamingrad"},"datePublished":"2019-04-24T07:33:51Z","url":"https://github.com/python/mypy/issues/6715"}
| 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:abfa4a4e-eeac-067a-5840-82c554c7a41a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A79E:44D65:4C2370:663761:6B002FD1 |
| html-safe-nonce | d0105b2462ac957407210376f7bf6ce5a84fa949bcdd90093802bfe4bdc86718 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzlFOjQ0RDY1OjRDMjM3MDo2NjM3NjE6NkIwMDJGRDEiLCJ2aXNpdG9yX2lkIjoiNTMyNTM5NTYyMjE1NTUzMDE5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5db83b8b078408c2030ab500e8d52f543a15d64086a7173e45484f9dec390b48 |
| hovercard-subject-tag | issue:436541080 |
| 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/6715/issue_layout |
| twitter:image | https://opengraph.githubassets.com/447d8d29ca3912fa1ed89f285fe049d36769cf745fe109b48cd0b87a8317604b/python/mypy/issues/6715 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/447d8d29ca3912fa1ed89f285fe049d36769cf745fe109b48cd0b87a8317604b/python/mypy/issues/6715 |
| og:image:alt | Summary of the issue: When using attrs to create a dataclass, adding a static method to the class with the same name as one of the attributes causes mypy to crash. I am happy to work on a fix here,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | leamingrad |
| 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