Better duck-typing with mypy-compatible extensions to Protocol
Project description
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: ...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file quacks-1.1.1.tar.gz
.
File metadata
- Download URL: quacks-1.1.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d53d26645cb5e1f68f963b15c0b388ce1a49a44ec818d26e39e84ed195b1987 |
|
MD5 | 0967fb612923295446e9993b21657b21 |
|
BLAKE2b-256 | 52ddfb139a911620070870de7f513f548d72241f37f1b0aff7b099fbb3c3af3b |
File details
Details for the file quacks-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: quacks-1.1.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef7bfb5d790de7b5807bfd8df2f5f56d1eeb985d6e75c3072dc50b8b93b2971a |
|
MD5 | 107c34fce639411d6cbd2c879161e8a7 |
|
BLAKE2b-256 | 06f422956c43a4b469f8b38430f962824eb18c6ea07ece8c6e44fd68a7968e19 |