a simple package
Project description
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'
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
Built Distribution
File details
Details for the file undefined-0.0.7.tar.gz
.
File metadata
- Download URL: undefined-0.0.7.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.22.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 282c2efeeffb1e422895bab80b9888de73b885043a8f4e68afdca7634d26023b |
|
MD5 | 6adfdbb79078c6c8df5c3880af451cc5 |
|
BLAKE2b-256 | 9b430cc082953a5ec32b2e126397655b8143f7092d3a6bf139bef48e8c2c0193 |
File details
Details for the file undefined-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: undefined-0.0.7-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.22.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 560a5f86fa96442b3ad350cc9b1c07982bf47f08549b2cd0f1e71a7a0ede9945 |
|
MD5 | 5c0b0657e6f893ccf372b9cc2770cbc0 |
|
BLAKE2b-256 | 47ef8e23666d6926e4969e676edfe3a3a6539a5bebf0cd76541fe552e0f19c55 |