Registry / serialization / niltype

niltype

JSON →
library1.0.2pypypi✓ verified 85d ago

A small Python library that provides a singleton `Nil` object. This object is designed to represent missing or unset values in scenarios where `None` is a valid and meaningful data value, thus avoiding ambiguity. Currently at version 1.0.2, it's a stable, single-purpose library with infrequent updates.

pip install niltype
INSTALL
IMPORT
SIG · NILTYPE
N
niltype
serializationpythonv1.0.2
Install
1.5s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.007s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Nil
from niltype import Nil

Demonstrates how to import and use the `Nil` singleton to distinguish between a truly missing value (represented by `Nil`) and an intentional `None` value in a function's return, especially useful for API responses or configuration.

from niltype import Nil def get_user_setting(user_id: int, setting_name: str): """Simulates fetching a user setting where Nil means 'not found'.""" if user_id == 1: if setting_name == "theme": return "dark" elif setting_name == "timeout": return None # None is a valid timeout (e.g., no timeout) return Nil # Setting does not exist for this user # Example usage: setting = get_user_setting(1, "theme") print(f"Theme setting: {setting} (is Nil: {setting is Nil})") setting = get_user_setting(1, "timeout") print(f"Timeout setting: {setting} (is Nil: {setting is Nil})") setting = get_user_setting(2, "language") print(f"Language setting: {setting} (is Nil: {setting is Nil})") if setting is Nil: print("\nSetting 'language' for user 2 is missing.") elif setting is None: print("\nSetting 'timeout' is explicitly set to None (no timeout).") else: print(f"\nSetting is {setting}.")
Debug
Known issues
gotchaThe `Nil` object evaluates to `False` in a boolean context, similar to `None`, empty collections, or zero. However, `Nil` is not `None` (`Nil != None`).
fix
Always use identity checks (`if obj is Nil:` or `if obj is not Nil:`) when specifically checking for the `Nil` singleton. Avoid `if not obj:` if you need to distinguish `Nil` from other falsey values.
affects: All versions
gotcha`Nil` is a true singleton, meaning there is only one instance of it throughout your application's lifetime. Any variable assigned `Nil` will reference this single instance.
fix
This is by design and fundamental to `niltype`. It implies `Nil` cannot carry state or attributes specific to a particular missing value context. If you need contextual information, wrap `Nil` in a custom class or use a different pattern.
affects: All versions
Errors
Common errors & fixes
AttributeError: 'NilType' object has no attribute 'some_property'
Attempting to access attributes or methods on a variable that holds `Nil` without first checking for its presence.
fix
Always check `if my_var is not Nil:` before attempting to access properties or methods on `my_var`, as `Nil` has no user-defined attributes.
TypeError: can't concat NilType to str
Passing `Nil` directly to functions or operations that expect a specific data type (e.g., string concatenation, arithmetic operations, database queries) and do not explicitly handle `Nil`.
fix
Implement explicit checks for `Nil` and handle it appropriately (e.g., return early, provide a default value, raise a more specific exception) before passing the variable to type-sensitive operations. For example: `my_str = 'Default' if my_var is Nil else str(my_var)`.
Upgrade
Version history
1.0.2latest on PyPI · released Sep 21, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
niltype — pip install niltype · libregistry