🦆 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": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.8.1",
"maintainer_email": null,
"keywords": "ducktyping, protocol, mypy, immutability",
"author": "Arie Bovenberg",
"author_email": "a.c.bovenberg@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/52/dd/fb139a911620070870de7f513f548d72241f37f1b0aff7b099fbb3c3af3b/quacks-1.1.1.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.1",
"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": "06f422956c43a4b469f8b38430f962824eb18c6ea07ece8c6e44fd68a7968e19",
"md5": "107c34fce639411d6cbd2c879161e8a7",
"sha256": "ef7bfb5d790de7b5807bfd8df2f5f56d1eeb985d6e75c3072dc50b8b93b2971a"
},
"downloads": -1,
"filename": "quacks-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "107c34fce639411d6cbd2c879161e8a7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.8.1",
"size": 6452,
"upload_time": "2024-10-19T17:56:59",
"upload_time_iso_8601": "2024-10-19T17:56:59.196430Z",
"url": "https://files.pythonhosted.org/packages/06/f4/22956c43a4b469f8b38430f962824eb18c6ea07ece8c6e44fd68a7968e19/quacks-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "52ddfb139a911620070870de7f513f548d72241f37f1b0aff7b099fbb3c3af3b",
"md5": "0967fb612923295446e9993b21657b21",
"sha256": "0d53d26645cb5e1f68f963b15c0b388ce1a49a44ec818d26e39e84ed195b1987"
},
"downloads": -1,
"filename": "quacks-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "0967fb612923295446e9993b21657b21",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.8.1",
"size": 4870,
"upload_time": "2024-10-19T17:57:01",
"upload_time_iso_8601": "2024-10-19T17:57:01.020392Z",
"url": "https://files.pythonhosted.org/packages/52/dd/fb139a911620070870de7f513f548d72241f37f1b0aff7b099fbb3c3af3b/quacks-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-19 17:57:01",
"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"
}