Phantom types for Python
Project description
phantom-types
Phantom types for Python will help you make illegal states unrepresentable and avoid shotgun parsing by enabling you to practice "Parse, don't validate".
This project is in early development and fundamental changes should be expected. Semantic versioning will be followed after version 1.0, but before that breaking changes might occur between minor versions.
Checkout the complete documentation on Read the Docs →
Installation
$ python3 -m pip install phantom-types
Example
from phantom import Phantom
from phantom.predicates.collection import contained
class Name(str, Phantom, predicate=contained({"Jane", "Joe"})):
...
def greet(name: Name):
print(f"Hello {name}!")
# This is valid.
greet(Name.parse("Jane"))
# And so is this.
joe = "Joe"
assert isinstance(joe, Name)
greet(joe)
# But this will yield a static type checking error.
greet("bird")
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
phantom-types-0.13.1.tar.gz
(17.8 kB
view details)
Built Distribution
File details
Details for the file phantom-types-0.13.1.tar.gz
.
File metadata
- Download URL: phantom-types-0.13.1.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aea13e36d0439cf5c1250b0cd94bafb1c9f45eda09e743fa5f702bd0196d5ea4 |
|
MD5 | 1e34cacb7716ee37ca3067bacf94f766 |
|
BLAKE2b-256 | a70a4322f752671996a4425d4e4edcbf67b44a2fb374d58bd686897c7d6a982b |
File details
Details for the file phantom_types-0.13.1-py3-none-any.whl
.
File metadata
- Download URL: phantom_types-0.13.1-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03f3865b550943b70c63d9c4aa63b2d9dea124918fd9061058e3aa91f8279cb8 |
|
MD5 | d70e3003e7f44957f8c954bd47e2353c |
|
BLAKE2b-256 | 7f48033106a5868a30438fc84332f2bff881f3bcf2afda31ab85fb7b228308d5 |