{"id":20098458,"url":"https://github.com/fluentpython/protocol_examples","last_synced_at":"2025-03-02T16:29:54.541Z","repository":{"id":146382806,"uuid":"268372025","full_name":"fluentpython/protocol_examples","owner":"fluentpython","description":"A PEP 544 protocol to support type hints for functions that sort","archived":false,"fork":false,"pushed_at":"2024-05-24T06:35:33.000Z","size":5596,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T03:45:18.097Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fluentpython.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-31T22:04:34.000Z","updated_at":"2024-05-24T06:35:37.000Z","dependencies_parsed_at":"2023-04-12T12:32:50.687Z","dependency_job_id":null,"html_url":"https://github.com/fluentpython/protocol_examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluentpython%2Fprotocol_examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluentpython%2Fprotocol_examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluentpython%2Fprotocol_examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluentpython%2Fprotocol_examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluentpython","download_url":"https://codeload.github.com/fluentpython/protocol_examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241536746,"owners_count":19978395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T17:03:53.930Z","updated_at":"2025-03-02T16:29:54.520Z","avatar_url":"https://github.com/fluentpython.png","language":"Python","readme":"# protocol_examples\n\nExamples using `typing.Protocol` from PEP 544\n\n## Notes\n\n### Classic Example: a \"file-like object\"\n\nFrom [_PEP 333 – Python Web Server Gateway Interface v1.0_](https://peps.python.org/pep-0333/) (2003):\n\n\n\u003e    To be considered “file-like”, the object supplied by the application\nmust have a `read()` method that takes an optional size argument.\n\nThe words \"file-like\" (or \"file like\") appear with similar implied meaning\nin the Python 3.12 distribution:\n\n- 148 times in the documentation;\n- 92 times in code comments (`.py` or `.c` source files).\n\nAlso, 30 times across 21 PEPs (100, 214, 258, 282, 305, 310, 333, 368, 400, 441, 444, 578, 680, 691, 3116, 3119, 3143, 3145, 3154, 3156, 3333).\n\n\nDefinition in `Lib/wsgiref/types.py`:\n\n```python\nclass _Readable(Protocol):\n    def read(self, size: int = ..., /) -\u003e bytes: ...\n```\n\n### Examples as of 2024-05-23\n\n`typing.Protocol` definitions found with `ripgrep`:\n\n```shell\nrg \"Protocol\\)\" -g '*.pyi' | sort\n```\n\n- 120 definitions on `typeshed/stdlib` (Python standard library)\n- 134 definitions on `typeshed/stubs` (external packages)\n\n\n\n### Cases to study\n\n- `importlib/resources/abc.py`: `class Traversable(Protocol)`\nwith several abstract and concrete methods, looks like an ABC but derives from `typing.Protocol`\n\n\n### Not `typing.Protocol`\n\n- `asyncio/protocols.py`: defines classes `BaseProtocol`, `Protocol` etc. for network protocols\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluentpython%2Fprotocol_examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluentpython%2Fprotocol_examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluentpython%2Fprotocol_examples/lists"}