Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: add Unset and UnsetType #116

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web_poet/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
17 changes: 17 additions & 0 deletions web_poet/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it should be capitalized as UNSET.