What you'd expect to find in the Python builtins
Project description
unbuiltins
Thoroughly tested and MyPy compatible constants and functions you'd expect to find in the Python builtins.
Install
requires python 3.8 or higher
pip install unbuiltins
Usage
from unbuiltins import *
Missing
Like the constant None
, Missing
can be used for e.g. optional function
arguments:
def say(value: Missable[str] = Missing):
if value is Missing:
print('*silence*')
else:
print(value)
frozendict
The builtins include frozenset
, but frozendict
is nowhere to be found
(see PEP 416).
frozendict
is basically an immutable and hashable dict
:
assert frozendict(spam='spam') == dict(spam='spam')
assert {frozendict(): 'empty'}[frozendict()] == 'empty'
It accepts generic type arguments and supports the merge (|
) operator,
like dict
since Python 3.9:
def add_eggs(value: frozendict[str, str]) -> frozendict[str, Union[str, int]]:
return value | dict(eggs=6)
assert 'eggs' in add_eggs(frozendict(spam='spam'))
first
Behaves identical to next
, but works for all iterables:
assert first([42, 666, 69]) == 42
assert first([], default='empty') == 'empty'
assert first(iter(dict(eggs=6))) == 'eggs'
filternone
Return those items of iterable
that are not None
:
assert list(filternone(['', None, 0, False])) == ['', 0, False]
either
Returns the first argument that is not None
or Missing
:
assert either(None, None, False) is False
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 unbuiltins-0.2.0.tar.gz
.
File metadata
- Download URL: unbuiltins-0.2.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d45a5a86dad25fde3bee6a907be8a14fb1f058de82d4f3225c1ad4f191f24fd |
|
MD5 | 68d374e8b8cd957fae8c74c1983ca777 |
|
BLAKE2b-256 | 68bca99b90b812f635d9d0f73fa2c76699f383ff35abcd5303dab98139d65d95 |
File details
Details for the file unbuiltins-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: unbuiltins-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50570acbcf022ec12659158c9e0f410cc4da480c65676703e2e59464a0e2dfc4 |
|
MD5 | a28276de0d03963b8d38de2952a8c7f1 |
|
BLAKE2b-256 | d8573ad4ffda25db4c0a20e52ee3850696cae7929b65dcb064c60c7f3113b84d |