Skip to content

Commit 3aab22f

Browse files
tmp
1 parent 1aecccb commit 3aab22f

8 files changed

Lines changed: 620 additions & 471 deletions

File tree

python/egglog/builtins.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,7 @@ def rebuild(self) -> Set[T]: ...
534534
converter(
535535
set,
536536
Set,
537-
lambda t: Set[get_type_args()[0]]( # type: ignore[misc,operator]
538-
*(convert(x, get_type_args()[0]) for x in t)
539-
),
537+
lambda t: Set(*(convert(x, get_type_args()[0]) for x in t)) if t else Set[get_type_args()[0]].empty(), # type: ignore[misc]
540538
)
541539

542540
SetLike: TypeAlias = Set[T] | set[TO]
@@ -639,9 +637,7 @@ def multiset_fold(f: Callable[[T, T], T], initial: T, xs: MultiSet[T]) -> T: ...
639637
converter(
640638
tuple,
641639
MultiSet,
642-
lambda t: MultiSet[get_type_args()[0]]( # type: ignore[misc,operator]
643-
*(convert(x, get_type_args()[0]) for x in t)
644-
),
640+
lambda t: MultiSet(*(convert(x, get_type_args()[0]) for x in t)) if t else MultiSet[get_type_args()[0]](), # type: ignore[operator,misc]
645641
)
646642

647643
MultiSetLike: TypeAlias = MultiSet[T] | tuple[TO, ...]
@@ -1035,9 +1031,7 @@ def map(self, fn: Callable[[T], V]) -> Vec[V]: ...
10351031
converter(
10361032
sequence_type,
10371033
Vec,
1038-
lambda t: Vec[get_type_args()[0]]( # type: ignore[misc,operator]
1039-
*(convert(x, get_type_args()[0]) for x in t)
1040-
),
1034+
lambda t: Vec(*(convert(x, get_type_args()[0]) for x in t)) if t else Vec[get_type_args()[0]].empty(), # type: ignore[misc]
10411035
)
10421036

10431037
VecLike: TypeAlias = Vec[T] | tuple[TO, ...] | list[TO]

python/egglog/conversion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def convert(source: object, target: type[V]) -> V:
118118
"""
119119
Convert a source object to a target type.
120120
"""
121-
assert isinstance(target, RuntimeClass)
121+
# if not issubclass(target, RuntimeClass):
122+
# raise TypeError(f"Expected target type to be a egglog type, got {target} of type {type(target)}")
122123
return cast("V", resolve_literal(target.__egg_tp__, source, target.__egg_decls_thunk__))
123124

124125

@@ -132,7 +133,7 @@ def convert_to_same_type(source: object, target: RuntimeExpr) -> RuntimeExpr:
132133

133134
def process_tp(tp: type | RuntimeClass) -> JustTypeRef | type:
134135
"""
135-
Process a type before converting it, to add it to the global declerations and resolve to a ref.
136+
Process a type before converting it, to add it to the global declarations and resolve to a ref.
136137
"""
137138
if isinstance(tp, RuntimeClass):
138139
_TO_PROCESS_DECLS.append(tp)

0 commit comments

Comments
 (0)