Title: stubgen generates an interface with invalid syntax for inheriting dataclass · Issue #12441 · python/mypy · GitHub
Open Graph Title: stubgen generates an interface with invalid syntax for inheriting dataclass · Issue #12441 · python/mypy
X Title: stubgen generates an interface with invalid syntax for inheriting dataclass · Issue #12441 · python/mypy
Description: Bug Report The stubgen command generates an interface with invalid syntax for a data class that inherits from another class located in a different file. To Reproduce Create a fresh virtual environment with Python >=3.7 and install mypy==...
Open Graph Description: Bug Report The stubgen command generates an interface with invalid syntax for a data class that inherits from another class located in a different file. To Reproduce Create a fresh virtual environm...
X Description: Bug Report The stubgen command generates an interface with invalid syntax for a data class that inherits from another class located in a different file. To Reproduce Create a fresh virtual environm...
Opengraph URL: https://github.com/python/mypy/issues/12441
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"stubgen generates an interface with invalid syntax for inheriting dataclass","articleBody":"**Bug Report**\r\n\r\nThe `stubgen` command generates an interface with invalid syntax for a data class that inherits from another class located in a different file.\r\n\r\n**To Reproduce**\r\n\r\n1. Create a fresh virtual environment with Python `>=3.7` and install `mypy==0.941`:\r\n```bash\r\npython3.9 -m venv venv\r\nsource venv/bin/activate\r\npip install -U pip\r\npip install mypy==0.941\r\n```\r\n2. Create a file named `a.py` with the following content:\r\n```python\r\nclass A:\r\n pass\r\n\r\n```\r\n3. Create a file named `b.py` in the same directory with the following content:\r\n```python\r\nfrom dataclasses import dataclass\r\nfrom a import A\r\n\r\n\r\n@dataclass\r\nclass B(A):\r\n c: str\r\n\r\n```\r\n4. Run `stubgen b.py -o .`\r\n5. Run `python b.pyi`\r\n\r\nThe generated `b.pyi` file has the following content:\r\n```python\r\nfrom a import A\r\n\r\nclass B(A):\r\n c: str\r\n def __init__(self, *, c, **) -> None: ...\r\n\r\n```\r\n\r\nNotes:\r\n- The stub generation works correctly if we don't annotate the class with `@dataclass`.\r\n- The stub generation works correctly if the superclass `A` is in the same file.\r\n- The stub generation works correctly if `B` doesn't inherit from `A`.\r\n\r\n**Expected Behavior**\r\n\r\nThe generated `b.pyi` file has valid Python syntax and the `python` command executes without errors.\r\n\r\n**Actual Behavior**\r\n\r\nThe generated `b.pyi` file doesn't have valid Python syntax and the command `python b.pyi` produces the following error:\r\n```python\r\n File \"/path/to/sandbox/b.pyi\", line 5\r\n def __init__(self, *, c, **) -> None: ...\r\n ^\r\nSyntaxError: invalid syntax\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: `0.941`. Reproducible with `0.940` as well. Cannot reproduce with `0.931`.\r\n- Mypy command-line flags: `-o`\r\n- Mypy configuration options from `mypy.ini` (and other config files): None\r\n- Python version used: `3.9.0`. Also reproduced with `3.7.12`, `3.8.5` and `3.10.0`. Cannot reproduce with `3.6.9`.\r\n- Operating system and version: `Ubuntu 20.04.3 LTS`. Also reproduced with `macOS Big Sur 11.5.2`\r\n- `pip list` output for Python 3.9.0:\r\n```bash\r\n$ pip list\r\nPackage Version\r\n----------------- -------\r\nmypy 0.941\r\nmypy-extensions 0.4.3\r\npip 22.0.4\r\nsetuptools 49.2.1\r\ntomli 2.0.1\r\ntyping_extensions 4.1.1\r\n```\r\n","author":{"url":"https://github.com/ivtoskov","@type":"Person","name":"ivtoskov"},"datePublished":"2022-03-24T17:13:10Z","url":"https://github.com/python/mypy/issues/12441"}
| 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:ab4344f4-a593-528a-b486-6de1340d643a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0BE:144E47:1A5FA58:21DF203:6AFFBB24 |
| html-safe-nonce | 8f9643f8f792e3c5626eb5e2e1496ad52154fa10a69c351be0eb168fcdf4d4e3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEJFOjE0NEU0NzoxQTVGQTU4OjIxREYyMDM6NkFGRkJCMjQiLCJ2aXNpdG9yX2lkIjoiNjczMjk2MTM4Njk0MDMxNjQ1MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2fceadc9fb1cd7d3498b29626b14606ceee259198281cd8597d93ade471b4ab5 |
| hovercard-subject-tag | issue:1179801870 |
| 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/12441/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5c2b81b85358a7c847a64aefd7d4fad12a7b1d6393d88385221ca03ad2fde276/python/mypy/issues/12441 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5c2b81b85358a7c847a64aefd7d4fad12a7b1d6393d88385221ca03ad2fde276/python/mypy/issues/12441 |
| og:image:alt | Bug Report The stubgen command generates an interface with invalid syntax for a data class that inherits from another class located in a different file. To Reproduce Create a fresh virtual environm... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ivtoskov |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7e461843db1c75e40d788c5cfd440d0e4ae1271cf19e06a798d0e7feb2d708f3 |
| 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 | d29a6a99861646939301302fab465f9f123b4773 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width