{"id":9981,"library":"niltype","title":"niltype: Singleton for Missing Values","description":"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.","status":"active","version":"1.0.2","language":"python","source_language":"en","source_url":"https://github.com/tsv1/niltype","tags":["singleton","missing values","null object","data validation","sentinel"],"install":[{"cmd":"pip install niltype","lang":"bash","label":"Install niltype"}],"dependencies":[],"imports":[{"symbol":"Nil","correct":"from niltype import Nil"}],"quickstart":{"code":"from niltype import Nil\n\ndef get_user_setting(user_id: int, setting_name: str):\n    \"\"\"Simulates fetching a user setting where Nil means 'not found'.\"\"\"\n    if user_id == 1:\n        if setting_name == \"theme\":\n            return \"dark\"\n        elif setting_name == \"timeout\":\n            return None # None is a valid timeout (e.g., no timeout)\n    return Nil # Setting does not exist for this user\n\n# Example usage:\nsetting = get_user_setting(1, \"theme\")\nprint(f\"Theme setting: {setting} (is Nil: {setting is Nil})\")\n\nsetting = get_user_setting(1, \"timeout\")\nprint(f\"Timeout setting: {setting} (is Nil: {setting is Nil})\")\n\nsetting = get_user_setting(2, \"language\")\nprint(f\"Language setting: {setting} (is Nil: {setting is Nil})\")\n\nif setting is Nil:\n    print(\"\\nSetting 'language' for user 2 is missing.\")\nelif setting is None:\n    print(\"\\nSetting 'timeout' is explicitly set to None (no timeout).\")\nelse:\n    print(f\"\\nSetting is {setting}.\")","lang":"python","description":"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."},"warnings":[{"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.","message":"The `Nil` object evaluates to `False` in a boolean context, similar to `None`, empty collections, or zero. However, `Nil` is not `None` (`Nil != None`).","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"`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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.0.2':43 'ambigu':39 'avoid':38 'current':40 'data':35,60 'design':19 'infrequ':53 'librari':9,51 'meaning':34 'miss':4,22,56 'nil':14 'niltyp':1 'none':29 'null':58 'object':15,17,59 'provid':11 'purpos':50 'python':8 'repres':21 'scenario':27 'sentinel':62 'singl':49 'single-purpos':48 'singleton':2,13,55 'small':7 'stabl':47 'thus':37 'unset':24 'updat':54 'valid':32,61 'valu':5,25,36,57 'version':42","created_at":"2026-04-17T01:21:45.521710+00:00","updated_at":"2026-04-17T01:21:45.521710+00:00","problems":[{"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.","cause":"Attempting to access attributes or methods on a variable that holds `Nil` without first checking for its presence.","error":"AttributeError: 'NilType' object has no attribute 'some_property'"},{"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)`.","cause":"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`.","error":"TypeError: can't concat NilType to str"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.2","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/tsv1/niltype","docs":null,"changelog":null,"pypi":"https://pypi.org/project/niltype/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}