Skip to main content

What you'd expect to find in the Python builtins

Project description

unbuiltins

PyPI version

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unbuiltins-0.2.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

unbuiltins-0.2.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

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

Hashes for unbuiltins-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5d45a5a86dad25fde3bee6a907be8a14fb1f058de82d4f3225c1ad4f191f24fd
MD5 68d374e8b8cd957fae8c74c1983ca777
BLAKE2b-256 68bca99b90b812f635d9d0f73fa2c76699f383ff35abcd5303dab98139d65d95

See more details on using hashes here.

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

Hashes for unbuiltins-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50570acbcf022ec12659158c9e0f410cc4da480c65676703e2e59464a0e2dfc4
MD5 a28276de0d03963b8d38de2952a8c7f1
BLAKE2b-256 d8573ad4ffda25db4c0a20e52ee3850696cae7929b65dcb064c60c7f3113b84d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page