🦆 Quacks
=========
.. image:: https://img.shields.io/pypi/v/quacks.svg
:target: https://pypi.python.org/pypi/quacks
.. image:: https://img.shields.io/pypi/l/quacks.svg
:target: https://pypi.python.org/pypi/quacks
.. image:: https://img.shields.io/pypi/pyversions/quacks.svg
:target: https://pypi.python.org/pypi/quacks
.. image:: https://github.com/ariebovenberg/quacks/actions/workflows/build.yml/badge.svg
:target: https://github.com/ariebovenberg/quacks/actions/workflows/build.yml
.. image:: https://img.shields.io/readthedocs/quacks.svg
:target: http://quacks.readthedocs.io/
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
.. epigraph::
If it walks like a duck and it quacks like a duck, then it must be a duck
Thanks to `PEP544 <https://www.python.org/dev/peps/pep-0544/>`_, Python now has protocols:
a way to define duck typing statically.
This library gives you some niceties to make common idioms easier.
Installation
------------
.. code-block:: bash
pip install quacks
⚠️ For type checking to work with ``mypy``, you'll need to enable the plugin in
your `mypy config file <https://mypy.readthedocs.io/en/latest/config_file.html>`_:
.. code-block:: ini
[mypy]
plugins = quacks
Features
--------
Easy read-only protocols
^^^^^^^^^^^^^^^^^^^^^^^^
Defining read-only protocols is great for encouraging immutability and
working with frozen dataclasses. Use the ``readonly`` decorator:
.. code-block:: python
from quacks import readonly
@readonly
class User(Protocol):
id: int
name: str
is_premium: bool
Without this decorator, we'd have to write quite a lot of cruft,
reducing readability:
.. code-block:: python
class User(Protocol):
@property
def id(self) -> int: ...
@property
def name(self) -> str: ...
@property
def is_premium(self) -> bool: ...
Raw data
{
"_id": null,
"home_page": "https://github.com/ariebovenberg/quacks",
"name": "quacks",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8.1,<4.0.0",
"maintainer_email": "",
"keywords": "ducktyping,protocol,mypy,immutability",
"author": "Arie Bovenberg",
"author_email": "a.c.bovenberg@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/17/cf/3048df96a2e5ede717ccdb8f3d709e7769537486a78fcd3b96d6bc19ae53/quacks-1.1.0.tar.gz",
"platform": null,
"description": "\ud83e\udd86 Quacks\n=========\n\n.. image:: https://img.shields.io/pypi/v/quacks.svg\n :target: https://pypi.python.org/pypi/quacks\n\n.. image:: https://img.shields.io/pypi/l/quacks.svg\n :target: https://pypi.python.org/pypi/quacks\n\n.. image:: https://img.shields.io/pypi/pyversions/quacks.svg\n :target: https://pypi.python.org/pypi/quacks\n\n.. image:: https://github.com/ariebovenberg/quacks/actions/workflows/build.yml/badge.svg\n :target: https://github.com/ariebovenberg/quacks/actions/workflows/build.yml\n\n.. image:: https://img.shields.io/readthedocs/quacks.svg\n :target: http://quacks.readthedocs.io/\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/psf/black\n\n.. epigraph::\n\n If it walks like a duck and it quacks like a duck, then it must be a duck\n\n\nThanks to `PEP544 <https://www.python.org/dev/peps/pep-0544/>`_, Python now has protocols:\na way to define duck typing statically.\nThis library gives you some niceties to make common idioms easier.\n\nInstallation\n------------\n\n.. code-block:: bash\n\n pip install quacks\n\n\u26a0\ufe0f For type checking to work with ``mypy``, you'll need to enable the plugin in\nyour `mypy config file <https://mypy.readthedocs.io/en/latest/config_file.html>`_:\n\n.. code-block:: ini\n\n [mypy]\n plugins = quacks\n\nFeatures\n--------\n\nEasy read-only protocols\n^^^^^^^^^^^^^^^^^^^^^^^^\n\nDefining read-only protocols is great for encouraging immutability and\nworking with frozen dataclasses. Use the ``readonly`` decorator:\n\n\n.. code-block:: python\n\n from quacks import readonly\n\n @readonly\n class User(Protocol):\n id: int\n name: str\n is_premium: bool\n\nWithout this decorator, we'd have to write quite a lot of cruft,\nreducing readability:\n\n\n.. code-block:: python\n\n class User(Protocol):\n @property\n def id(self) -> int: ...\n @property\n def name(self) -> str: ...\n @property\n def is_premium(self) -> bool: ...\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Better duck-typing with mypy-compatible extensions to Protocol",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/ariebovenberg/quacks",
"Repository": "https://github.com/ariebovenberg/quacks"
},
"split_keywords": [
"ducktyping",
"protocol",
"mypy",
"immutability"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "11ee67d344bee9582dfbcb651a5420cfee91afe03b37de3ee829f06acf2740ac",
"md5": "962f0314de679b993449349f8ab67bc7",
"sha256": "a83f128a1b1c79c73630abe08b4856c9a06483377e72436d94775734e33313fa"
},
"downloads": -1,
"filename": "quacks-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "962f0314de679b993449349f8ab67bc7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.1,<4.0.0",
"size": 6422,
"upload_time": "2023-12-07T16:52:36",
"upload_time_iso_8601": "2023-12-07T16:52:36.969291Z",
"url": "https://files.pythonhosted.org/packages/11/ee/67d344bee9582dfbcb651a5420cfee91afe03b37de3ee829f06acf2740ac/quacks-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "17cf3048df96a2e5ede717ccdb8f3d709e7769537486a78fcd3b96d6bc19ae53",
"md5": "3aec634ce9f88b0b5823169fbf7c712c",
"sha256": "9716414b99e3630fa5a36dc6978b9bf942f21ac87679a183fb92a9f7281c4b37"
},
"downloads": -1,
"filename": "quacks-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "3aec634ce9f88b0b5823169fbf7c712c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.1,<4.0.0",
"size": 4823,
"upload_time": "2023-12-07T16:52:38",
"upload_time_iso_8601": "2023-12-07T16:52:38.684827Z",
"url": "https://files.pythonhosted.org/packages/17/cf/3048df96a2e5ede717ccdb8f3d709e7769537486a78fcd3b96d6bc19ae53/quacks-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-07 16:52:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ariebovenberg",
"github_project": "quacks",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "quacks"
}