Skip to content

Commit b091610

Browse files
committed
models: Add support for doublesplat (**)
1 parent 734a152 commit b091610

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

gel/_internal/_codegen/_models/_pydantic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3914,7 +3914,7 @@ def _write_object_type_qb_methods(
39143914
builtin_str = self.import_name("builtins", "str")
39153915
callable_ = self.import_name("collections.abc", "Callable")
39163916
literal_ = self.import_name("typing", "Literal")
3917-
literal_star = f'{literal_}["*"]'
3917+
literal_star = f'{literal_}["*", "**"]'
39183918
tuple_ = self.import_name("builtins", "tuple")
39193919
expr_proto = self.import_name(BASE_IMPL, "ExprCompatible")
39203920
py_const = self.import_name(BASE_IMPL, "PyConstType")

gel/_internal/_qbmodel/_abstract/_base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ class AbstractGelModelMeta(GelTypeMeta):
143143
weakref.WeakValueDictionary[uuid.UUID, type[Any]]
144144
] = weakref.WeakValueDictionary()
145145

146-
if TYPE_CHECKING:
147-
# Splat qb protocol
148-
def __iter__(cls) -> Iterator[_qb.ShapeElement]: ...
146+
# Splat qb protocol
147+
def __iter__(cls) -> Iterator[_qb.ShapeElement]:
148+
cls = cast("type[AbstractGelModel]", cls)
149+
shape = _qb.get_object_type_splat(cls)
150+
return iter(shape.elements)
149151

150152
def __new__(
151153
mcls,

gel/_internal/_qbmodel/_abstract/_expressions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _const_to_expr(
117117
def select(
118118
cls: type[AbstractGelModel],
119119
/,
120-
*elements: _qb.ShapeElement | Literal["*"],
120+
*elements: _qb.ShapeElement | Literal["*", "**"],
121121
__operand__: _qb.ExprAlias | None = None,
122122
**kwargs: bool | _Value,
123123
) -> _qb.ShapeOp:
@@ -144,6 +144,12 @@ def select(
144144
for elem in elements:
145145
if elem == "*":
146146
shape_elements.extend(iter(cls))
147+
elif elem == "**":
148+
shape_elements.extend(
149+
_qb.Shape.splat(
150+
source=this_type, kind=_qb.Splat.DOUBLESTAR
151+
).elements
152+
)
147153
else:
148154
shape_elements.append(elem)
149155

gel/_internal/_qbmodel/_abstract/_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __gel_assert_single__(
8989
def select(
9090
cls,
9191
/,
92-
*elements: _qb.PathAlias | Literal["*"],
92+
*elements: _qb.PathAlias | Literal["*", "**"],
9393
__operand__: _qb.ExprAlias | None = None,
9494
**kwargs: Any,
9595
) -> type[Self]:

gel/_internal/_qbmodel/_pydantic/_models.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@
5050
from . import _fields
5151

5252
if TYPE_CHECKING:
53-
from collections.abc import (
54-
Iterator,
55-
Mapping,
56-
)
53+
from collections.abc import Mapping
5754
from gel._internal._qbmodel._abstract import GelType
5855

5956

@@ -276,12 +273,6 @@ def __setattr__(cls, name: str, value: Any, /) -> None: # noqa: N805
276273
else:
277274
super().__setattr__(name, value)
278275

279-
# Splat qb protocol
280-
def __iter__(cls) -> Iterator[_qb.ShapeElement]: # noqa: N805
281-
cls = cast("type[GelModel]", cls)
282-
shape = _qb.get_object_type_splat(cls)
283-
return iter(shape.elements)
284-
285276
def __gel_pointers__(cls) -> Mapping[str, type[GelType]]: # noqa: N805
286277
cls = cast("type[GelModel]", cls)
287278
result = _model_pointers_cache.get(cls)

tests/test_qb.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ def test_qb_filter_06(self):
294294
self.assertEqual(res.name, "red")
295295
self.assertEqual(res.count, 2)
296296

297-
@tb.xfail
298297
def test_qb_filter_07(self):
299298
from models import default
300299

@@ -693,7 +692,6 @@ def test_qb_delete_02(self):
693692
[p.body for p in after], ["*magic stuff*", "I'm Cameron"]
694693
)
695694

696-
@tb.xfail
697695
def test_qb_delete_03(self):
698696
from models import default
699697

0 commit comments

Comments
 (0)