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.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file unbuiltins-0.2.2.tar.gz.

File metadata

  • Download URL: unbuiltins-0.2.2.tar.gz
  • Upload date:
  • Size: 17.2 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.2.tar.gz
Algorithm Hash digest
SHA256 a890382a5d0d24b0f510953123265c34f3e0c542ac33d8fea7379eac2ab2e1ac
MD5 fe68cbae8927df82c16e9a7c622bbf61
BLAKE2b-256 910ab4abafa6bc120a3e10832f574649edf0255e3ef007fd1a601dbdc9f87994

See more details on using hashes here.

File details

Details for the file unbuiltins-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: unbuiltins-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c696aebf9d6fd50bac64c51e47126f7cbde6122e4d458b8594cd3bbc038498b7
MD5 cb396a62e1a97979ddd324c4e46fcca5
BLAKE2b-256 564ce6bc439980d112955a37e476314b3978ad2999c79767db04099bfcd90aad

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