-
Notifications
You must be signed in to change notification settings - Fork 0
Release 0.4.4: async tasks, nested refs, and hash correctness #22
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
Changes from all commits
59b11bd
a197b52
8c72e91
abac95d
ddc51a5
094f8ec
77f040e
a74c439
af67a66
b947711
2b2b29d
6a0bf48
83d34f8
87bc38a
a8345d4
9f171e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,15 +18,41 @@ def __init__(self, key: int | str) -> None: | |||||
| self.key = key | ||||||
|
|
||||||
|
|
||||||
| def _collect_input_refs(value: Any, refs: list[ObjectRef], visited: set[int]) -> None: | ||||||
| if hasattr(value, "__cashet_ref__"): | ||||||
| refs.append(value.__cashet_ref__()) | ||||||
| return | ||||||
| value_id = id(value) | ||||||
| if value_id in visited: | ||||||
| return | ||||||
| if isinstance(value, dict): | ||||||
| visited.add(value_id) | ||||||
| for key, val in value.items(): | ||||||
| _collect_input_refs(key, refs, visited) | ||||||
| _collect_input_refs(val, refs, visited) | ||||||
| visited.discard(value_id) | ||||||
| elif isinstance(value, list | tuple | set | frozenset): | ||||||
| visited.add(value_id) | ||||||
| for item in value: | ||||||
| _collect_input_refs(item, refs, visited) | ||||||
| visited.discard(value_id) | ||||||
|
|
||||||
|
|
||||||
| def resolve_input_refs(args: tuple[Any, ...], kwargs: dict[str, Any]) -> list[ObjectRef]: | ||||||
| refs: list[ObjectRef] = [] | ||||||
| visited: set[int] = set() | ||||||
| for arg in args: | ||||||
| if hasattr(arg, "__cashet_ref__"): | ||||||
| refs.append(arg.__cashet_ref__()) | ||||||
| _collect_input_refs(arg, refs, visited) | ||||||
| for val in kwargs.values(): | ||||||
| if hasattr(val, "__cashet_ref__"): | ||||||
| refs.append(val.__cashet_ref__()) | ||||||
| return refs | ||||||
| _collect_input_refs(val, refs, visited) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The _collect_input_refs function appends refs without deduplication. If the same ref appears multiple times across nested containers, the commit hash changes unnecessarily because the duplicate hashes are included. Deduplicate refs by their hash before returning.
Suggested change
|
||||||
| unique_refs: list[ObjectRef] = [] | ||||||
| seen: set[str] = set() | ||||||
| for ref in refs: | ||||||
| if ref.hash in seen: | ||||||
| continue | ||||||
| seen.add(ref.hash) | ||||||
| unique_refs.append(ref) | ||||||
| return unique_refs | ||||||
|
|
||||||
|
|
||||||
| class AsyncResultRef(Generic[T]): | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When resolving items inside a frozenset, a resolved value may be unhashable (e.g., a list from a ref), causing a TypeError when constructing the frozenset. Add a hashability check before creating the frozenset.