GitXplorerGitXplorer
a

quacks

public
15 stars
1 forks
4 issues

Commits

List of commits on branch main.
Verified
afc0695d02d36876f21f9fd9d227d1f69393a401

Merge pull request #170 from ariebovenberg/dependabot/pip/pytest-8.3.3

aariebovenberg committed 9 days ago
Verified
69515a18cd6d8ef3a9e56d41253725aa6dc5a6a5

chore(deps-dev): bump pytest from 8.3.2 to 8.3.3

ddependabot[bot] committed 9 days ago
Verified
25279a006077e4bf9262f14d89b0c9771e35343a

Merge pull request #169 from ariebovenberg/dependabot/pip/mypy-1.11.2

aariebovenberg committed 25 days ago
Verified
e37d2229bd82838580c948bd7eb0cbafd1c2dcbc

chore(deps-dev): bump mypy from 1.11.1 to 1.11.2

ddependabot[bot] committed 25 days ago
Verified
6b33af3f96221bdfffa0fbaf0fe403948c774ded

Merge pull request #167 from ariebovenberg/dependabot/pip/flake8-7.1.1

aariebovenberg committed a month ago
Verified
5e5964b98157b314bc6d8bb4d3f7b317e1cf408a

Merge pull request #168 from ariebovenberg/dependabot/pip/black-24.8.0

aariebovenberg committed a month ago

README

The README file for this repository.

🦆 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: ...