Title: Not resolving nested protocol when combined through multiple inheritance · Issue #5998 · python/mypy · GitHub
Open Graph Title: Not resolving nested protocol when combined through multiple inheritance · Issue #5998 · python/mypy
X Title: Not resolving nested protocol when combined through multiple inheritance · Issue #5998 · python/mypy
Description: Are you reporting a bug, or opening a feature request? This may be a bug if it is not intended behavior. Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try...
Open Graph Description: Are you reporting a bug, or opening a feature request? This may be a bug if it is not intended behavior. Please insert below the code you are checking with mypy, or a mock-up repro if the source is...
X Description: Are you reporting a bug, or opening a feature request? This may be a bug if it is not intended behavior. Please insert below the code you are checking with mypy, or a mock-up repro if the source is...
Opengraph URL: https://github.com/python/mypy/issues/5998
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Not resolving nested protocol when combined through multiple inheritance","articleBody":"* Are you reporting a bug, or opening a feature request?\r\n\r\nThis may be a bug if it is not intended behavior.\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\nI've constructed the following minimal example that demonstrates the issue. I've placed a comment before the line where mypy is having a problem.\r\n\r\n```python\r\nfrom dataclasses import dataclass\r\nfrom typing import List\r\n\r\nfrom typing_extensions import Protocol\r\n\r\n\r\nclass Name(Protocol):\r\n first: str\r\n last: str\r\n\r\n\r\nclass HasWand(Protocol):\r\n has_wand: bool\r\n\r\n\r\nclass NameProp(Protocol):\r\n name: Name\r\n\r\n\r\nclass Wizard(NameProp, HasWand, Protocol): ...\r\n\r\n\r\ndef wand_report(arg: Wizard) -> None:\r\n print(arg.name.first)\r\n print(arg.name.last)\r\n if arg.has_wand:\r\n print('This wizard has a wand.')\r\n else:\r\n print('This wizard needs to visit Ollivanders.')\r\n\r\n\r\n@dataclass\r\nclass NameExtended:\r\n first: str\r\n last: str\r\n middle_names: List[str]\r\n\r\n\r\n@dataclass\r\nclass DarkWizard:\r\n name: NameExtended\r\n at_large: bool\r\n power_level: int\r\n has_wand: bool = True\r\n\r\n\r\ncarl = DarkWizard(\r\n name=NameExtended(\r\n first='Carl',\r\n last='Fizzlbuz',\r\n middle_names=['Modfife']\r\n ),\r\n power_level=2,\r\n at_large=True,\r\n)\r\n\r\n# Pycharm is fine with the following line, as I'd expect, since 'NameExtended'\r\n# structurally implements 'Name'. mypy complains about this line.\r\nwand_report(carl)\r\n```\r\n* What is the actual behavior/output?\r\n\r\n```\r\nnest_protocols.py:59: error: Argument 1 to \"wand_report\" has incompatible type \"DarkWizard\"; expected \"Wizard\"\r\nnest_protocols.py:59: note: Following member(s) of \"DarkWizard\" have conflicts:\r\nnest_protocols.py:59: note: name: expected \"Name\", got \"NameExtended\"\r\n```\r\n\r\n* What is the behavior/output you expect?\r\nI would expect no error to be raised for the file above with the --strict flag.\r\n* What are the versions of mypy and Python you are using?\r\nmypy 0.641\r\nPython 3.7.1\r\n* Do you see the same issue after installing mypy from Git master?\r\nYes\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n--strict\r\n\r\n","author":{"url":"https://github.com/willtalmadge","@type":"Person","name":"willtalmadge"},"datePublished":"2018-12-03T21:52:27Z","url":"https://github.com/python/mypy/issues/5998"}
| 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:ea6fe41a-9db4-8f5b-7391-1fbfab8b5f93 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B12E:3E19F2:10AFDDA:15F9619:6B000A6C |
| html-safe-nonce | 7218b7e9b4f49f88a76648a2c1ab7fbc2884f00f7542259d1c882360db9fdbe5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTJFOjNFMTlGMjoxMEFGRERBOjE1Rjk2MTk6NkIwMDBBNkMiLCJ2aXNpdG9yX2lkIjoiNTkxNDI3MzA0MzMwNzMwMTQ4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5396302ab4b140d38f386b2053b65e73793d86415a8818cfa1cfb04323f2b7ad |
| hovercard-subject-tag | issue:387021903 |
| 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/5998/issue_layout |
| twitter:image | https://opengraph.githubassets.com/581751df398c3f6bb45e50c28aadf34bfbf3fd59f68db8bf5b5263b1c493bc5d/python/mypy/issues/5998 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/581751df398c3f6bb45e50c28aadf34bfbf3fd59f68db8bf5b5263b1c493bc5d/python/mypy/issues/5998 |
| og:image:alt | Are you reporting a bug, or opening a feature request? This may be a bug if it is not intended behavior. Please insert below the code you are checking with mypy, or a mock-up repro if the source is... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | willtalmadge |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width