Skip to main content

Undefined

Ever needed a global object that act as None but not quite ?

Like for example key-word argument for function, where None make sens, so you need a default value.

One solution is to create as singleton object:

mysingleton = object()

Though it becomes difficult to track the singleton across libraries, and teach users where to import this from.

It's also relatively annoying use this singleton across library.

Introducing undefined:

>>> import undefined
>>> from undefined import Undefined
>>> undefined is Undefined
True

behavior

It work (for now) mostly like a singleton object

Though it's neither truthy not falsy

>>> if undefined: print(True)
raise NotImplementedError

Casing ?

Because it is a module you can use it lowercase:

import undefined

Because it looks more like a keyword (None, True, False), you can use it upper case:

import undefined as Undefined

or

from undefined import Undefined

I tend to be torn between lowercase, for simplicity, and Uppercase.

Why not None, difference with None

undefined is likely slower, and as it is a regular Python object there are a few on purpose (or not difference).

Unlike None, you can assign to it

>>> None = 3 
SyntaxError: can't assign to keyword
>>> undefined = 3
>>> undefned
3

Unlike None, undefined is mutable

>>> undefined.value = 42
>>> undefined.value
42

(might be able to fix that with __get_attr__

Unlike None, undefined is neither true not false.

If you test for boolean value of undefind if will raise. That is to say: the following will fail:

value = undefined
if value:
   pass # will raise before reaching here.

You have to check for identity:

value = undefined
other = 1
if value is undefined:
    pass # will execute

for info, undefined is not True,False, not undefined with respect to identity

>>> undefined is True
False

>>> undefined is False
False

>>>: undefined is None
False

String form

str(undefined) raises. repr(undefined) is the unicode string 'Undefined'

Release files for undefined 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for undefined 0.0.8
File Size Uploaded
undefined-0.0.8.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for undefined 0.0.8
File Interpreter ABI Platform
undefined-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 8.0 kB

Release files / undefined-0.0.8.tar.gz

Download URL undefined-0.0.8.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c6f237c0e3d7e7519694b21bd471dc25ee3c3379d9c23b74ebf02aa349c5cff7
BLAKE2b-256 checksum
How to use checksums
78b2af4330ffa42fc9c41533b06cdc95ac780f41cf4d3cb9c71f973847d0c398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release files / undefined-0.0.8-py3-none-any.whl

Download URL undefined-0.0.8-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e081023fd5c7d6bd83a3e2da51fce4314878b4d4cc555ade79b7fc0ef3211e9
BLAKE2b-256 checksum
How to use checksums
8a6e105abbbc21c39e835a2734325b1737934ad02259ea372f2c6a783fca1df1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page