diff --git a/web_poet/__init__.py b/web_poet/__init__.py index 3c8b0112..c0212889 100644 --- a/web_poet/__init__.py +++ b/web_poet/__init__.py @@ -1,4 +1,4 @@ -from .fields import field, item_from_fields, item_from_fields_sync +from .fields import Unset, UnsetType, field, item_from_fields, item_from_fields_sync from .page_inputs import ( BrowserHtml, HttpClient, diff --git a/web_poet/fields.py b/web_poet/fields.py index d85fd93d..92acbd84 100644 --- a/web_poet/fields.py +++ b/web_poet/fields.py @@ -178,3 +178,20 @@ def _without_unsupported_field_names( if item_field_names is None: # item_cls doesn't define field names upfront return field_names[:] return list(set(field_names) & set(item_field_names)) + + +# TODO: enforce singleton +class UnsetType: + def __repr__(self) -> str: + return "Unset" + + def __str__(self) -> str: + return self.__repr__() + + def __bool__(self) -> bool: + return False + + +# Represents a field that hasn't been set with any values instead of being +# None. +Unset = UnsetType()