🦆 Quacks

https://img.shields.io/pypi/v/quacks.svg https://img.shields.io/pypi/l/quacks.svg https://img.shields.io/pypi/pyversions/quacks.svg https://github.com/ariebovenberg/quacks/actions/workflows/build.yml/badge.svg https://img.shields.io/readthedocs/quacks.svg https://img.shields.io/badge/code%20style-black-000000.svg

If it walks like a duck and it quacks like a duck, then it must be a duck

Thanks to PEP544, Python now has protocols: a way to define duck typing statically. This library gives you some niceties to make common idioms easier.

Installation

pip install quacks

⚠️ For type checking to work with mypy, you’ll need to enable the plugin in your mypy config file:

[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:

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:

class User(Protocol):
    @property
    def id(self) -> int: ...
    @property
    def name(self) -> str: ...
    @property
    def is_premium(self) -> bool: ...

Contents

Changelog

Next release

1.1.0 (2023-12-07)

  • 🐍 Add official Python 3.12 support, drop Python 3.7 support.

  • 🗑️ No dependencies anymore!

1.0.0 (2023-02-03)

  • 🦺 First 1.x release. Semantic versioning will be used to indicate potential breaking changes in the future.

  • 🐍 Add official Python 3.11 support.

  • 👌 Simplify name of mypy plugin from quacks.mypy to quacks. The old name is still accessible for backwards compatibility.

0.2.0 (2022-01-04)

  • Drop Python 3.6 support.

0.1.3 (2021-12-15)

  • More documentation improvements.

0.1.2 (2021-12-12)

  • Improvements to documentation.

0.1.1 (2021-12-12)

  • Fix issue with using TypeVar and forward declarations with readonly.

0.1.0 (2021-12-12)

  • Add @readonly decorator.

0.0.1 (2021-12-10)

  • Initial release.

Indices and tables