Skip to content
Merged
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
19 changes: 19 additions & 0 deletions cosmodol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
CosmosAccount,
CosmosDatabase,
)
from cosmodol.ops import (
BATCH_OPS,
add_container,
add_database,
batch_items,
delete_container,
delete_database,
partition,
replace_item,
)
from cosmodol.recipes import (
cosmos_store,
strip_system_fields,
Expand Down Expand Up @@ -94,6 +104,15 @@
# trees
"CosmosAccount",
"CosmosDatabase",
# key-taking operations (free functions; honour dol wrappers)
"BATCH_OPS",
"add_container",
"add_database",
"batch_items",
"delete_container",
"delete_database",
"partition",
"replace_item",
# recipes
"cosmos_store",
"strip_system_fields",
Expand Down
25 changes: 25 additions & 0 deletions cosmodol/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,28 @@ def wrapper(*args, **kwargs):
return wrapper

return decorator


class MovedToFunction:
"""Class attribute marking a method that moved to a free function.

Instance access raises an ``AttributeError`` naming the replacement, so
``hasattr(store, name)`` is ``False`` and the error says where to go. Class access
returns the marker itself, which keeps ``dol``'s class-wrapping (``delegate_to``
walks ``dir(cls)``) working.
"""

def __init__(self, replacement: str, *, reason: str = ""):
self.replacement = replacement
self.reason = reason

def __set_name__(self, owner, name):
self.name = name

def __get__(self, instance, owner=None):
if instance is None:
return self
raise AttributeError(
f"{type(instance).__name__}.{self.name} was removed; use "
f"`{self.replacement}`. {self.reason}".rstrip()
)
Loading
Loading