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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: unbuiltins-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5

File hashes

Hashes for unbuiltins-0.1.0.tar.gz
Algorithm Hash digest
SHA256 256ace4bffcb5e8d6b1f57a508ace7dc0662da7ee082ecd0d9e645e63fe82c8d
MD5 210e669a0ae651d063205a2280e35e14
BLAKE2b-256 423587422d5dca5072fe500b93a3819e7a96312cb3801ec165146c588f0c5a1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unbuiltins-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5

File hashes

Hashes for unbuiltins-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf25f5e065a9dcdf5de80b8f8f58930a2195dc4fc05ba1ecce1c764611cb368c
MD5 e705d4233278c24f5e9500bd54b7c483
BLAKE2b-256 32733abca8e61b2875e08291e435afa7798275ff080736cd4fadbeaedffac978

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