Title: Should concrete implementations be required to implement protocol? · Issue #8926 · python/mypy · GitHub
Open Graph Title: Should concrete implementations be required to implement protocol? · Issue #8926 · python/mypy
X Title: Should concrete implementations be required to implement protocol? · Issue #8926 · python/mypy
Description: Are you reporting a bug, or opening a feature request? Bug 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 to simplify your case to a minimal repro. fro...
Open Graph Description: Are you reporting a bug, or opening a feature request? Bug 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 to si...
X Description: Are you reporting a bug, or opening a feature request? Bug 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 to si...
Opengraph URL: https://github.com/python/mypy/issues/8926
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Should concrete implementations be required to implement protocol?","articleBody":"* Are you reporting a bug, or opening a feature request?\r\n\r\nBug\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\n```python\r\n\r\nfrom typing import Protocol\r\n\r\n\r\nclass Person(Protocol):\r\n first_name: str\r\n\r\n def greeting(self, message: str) -> str:\r\n ...\r\n\r\n\r\nclass FrenchPerson(Person):\r\n prenom: str\r\n\r\n def __init__(self, name: str):\r\n self.prenom = name\r\n\r\n def salutation(self, message: str) -> str:\r\n return f\"{message} {self.prenom}\"\r\n\r\n\r\ndef print_person(person: Person) -> str:\r\n return person.greeting(message=\"Je m'appelle\")\r\n\r\n\r\ndef main():\r\n fp = FrenchPerson(name='Henri')\r\n response = print_person(fp)\r\n print(response)\r\n```\r\n\r\n* What is the actual behavior/output?\r\n\r\nPEP 544 says you can state that an implementation supports a protocol by\r\n[subclassing the protocol](https://www.python.org/dev/peps/pep-0544/#explicitly-declaring-implementation).\r\n\r\nIt also says: \"If one omits Protocol in the base class list, this would\r\nbe a regular (non-protocol) class that must implement Sized.\"\r\n\r\n* What is the behavior/output you expect?\r\n\r\nI would hope `mypy` would, either at declaration time or in the `print_person` function, spot that something claimed to be a `Person` but had neither the protocol variable `name` nor the method `greeting`.\r\n\r\nIt's also a shame that `FrenchPerson` got the `greeting` method added to it from the subclassing.\r\n\r\n* What are the versions of mypy and Python you are using?\r\n\r\n`mypy` 0.770 and Python 3.8.1\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n\r\nNone.\r\n","author":{"url":"https://github.com/pauleveritt","@type":"Person","name":"pauleveritt"},"datePublished":"2020-05-31T12:04:13Z","url":"https://github.com/python/mypy/issues/8926"}
| 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:18d94698-4ae9-0683-4b33-423e13964591 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C38A:22BD05:23E7B39:30BBB24:6B002FCF |
| html-safe-nonce | 3fbf411d6558bd4934a3a0400fb506a3745b73c3da5e8e873a2170c82a533b0f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzhBOjIyQkQwNToyM0U3QjM5OjMwQkJCMjQ6NkIwMDJGQ0YiLCJ2aXNpdG9yX2lkIjoiNjQ0NTY2NjgwMjU1ODA1NDM1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8bd66384b189bf69c1cc50423ee6fb5fcffa6f29932b502dcbb02832313b8d8a |
| hovercard-subject-tag | issue:627949531 |
| 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/8926/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a578ab92b7f9d8baeaa9a85d13352b9fdcc8e59c0983980c3a110bb7334098ff/python/mypy/issues/8926 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a578ab92b7f9d8baeaa9a85d13352b9fdcc8e59c0983980c3a110bb7334098ff/python/mypy/issues/8926 |
| og:image:alt | Are you reporting a bug, or opening a feature request? Bug 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 to si... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pauleveritt |
| 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