A collection of useful types for Python, to drive correctness in your programs.
Project description
Sensible Types
A collection of useful types for Python, to drive correctness in your programs.
Why?
Parse, don't validate.
How many times have you written code of this nature?
def foo(a: int):
if a < 0:
raise ValueError(f"The input `a` should be positive. Actual value: {a}")
# actual logic
...
The requirement for input validation indicates an error in your type system.
It should not be possible to pass a negative int to a function that can only work with a positive int — that is an invalid state that your program should never find itself in.
Unfortunately, Python doesn't make this easy. We should ideally be able to do something like this:
def foo(a: uint):
# straight into the logic, as the input comes pre-validated
...
But of course, Python does not have an unsigned integer type.
Type-driven design leads to more correct, reliable software, where tests only have to focus on verifying that your business logic works rather than verifying that your inputs are valid. To borrow a phrase from Rust 🦀, it makes invalid states unrepresentable.
This package aims to provide new primitive types with additional constraints that are commonly required.
For now, it only contains PositiveInt, but it may be extended in the future as new use cases arise.
But Python doesn't care about types at runtime
You're right.
But that doesn't mean that you, the developer, should not care about the correctness and reliability of your program.
You should be using strict type checking tools like Pyright to analyse your code. Without such tools, all the type-driven design in the world won't save you from Python.
There still won't be anything stopping your program from running if you pass in an incorrect type, but at least you'll see errors in you IDE if you've written incorrect code.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sensible_types-0.1.1.tar.gz.
File metadata
- Download URL: sensible_types-0.1.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.28
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73b9591618002e775eb4798ffcc400dbd9356b2f41909e8aa5f8e9401eba73d7
|
|
| MD5 |
2c769fdc5c455f5c7634175728a9bfa3
|
|
| BLAKE2b-256 |
43bbbeb2ae65f7fd2d993c87872d184d032133e0eed15251dfffa585e562dde3
|
File details
Details for the file sensible_types-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sensible_types-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.28
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01a66aab21f6169e73689b4c37989cebc2e3fbc1d6fc403d60d6fd4ec18f1db6
|
|
| MD5 |
6b5112ec1cabe3337bc63c09ee3c3468
|
|
| BLAKE2b-256 |
8b550e1a3a442393b8248487e958ac5befa22589c10f2e288f26c77f6b231f34
|