Distinguishing None from Empty Collections in Form Initialization
When analyzing the initialization logic of Djengo forms, the determination of a bound state relies on explicit identity checks rather than truthiness evaluatiosn. The core mechanism assigns the bound status based on whether submitted data or files exist.
class BaseForm:
def __init__(self, payload=None, attachments=None):
# Bound state depends on explicit presence of arguments
self._is_bound = payload is not None or attachments is not None
self._payload = payload or {}
self._attachments = attachments or {}
In this context, the expression payload is not None evaluates strictly against the None singleton. It does not treat empty containers as falsey in this specific comparison. Consider the following behavior in a Python interpreter:
>>> items = []
>>> mapping = {}
>>> items is not None
True
>>> mapping is not None
True
>>> mapping['key'] = 'value'
>>> mapping is not None
True
>>> items = None
>>> items is not None
False
Both empty lists and empty dictionaries satisfy the condition is not None. The check specifically targets the absence of an object reference rather than the contents within a collection. None signifies that no argument was passed, whereas an empty list or dictionary indicates an argument was passed, but it contains no elements. This distinction ensures that forms can differentiate between no submission and an empty submission.