@@ -126,7 +126,7 @@ def _card_impl(
126
126
wrapper = card_body
127
127
128
128
attrs , children = consolidate_attrs (* args , class_ = class_ , ** kwargs )
129
- children = _wrap_children_in_card (* children , wrapper = wrapper )
129
+ children = _as_card_items (* children , wrapper = wrapper )
130
130
131
131
tag = div (
132
132
{
@@ -202,9 +202,9 @@ def __call__(self, *args: TagChild) -> CardItem:
202
202
203
203
204
204
def _as_card_items (
205
- * children : TagChild | CardItem | None , # `TagAttrs` are not allowed here
205
+ * children : TagChild , # `TagAttrs` are not allowed here
206
206
wrapper : WrapperCallable | None ,
207
- ) -> list [CardItem ]:
207
+ ) -> list [TagChild ]:
208
208
# We don't want `None`s creating empty card bodies
209
209
children_vals = [child for child in children if child is not None ]
210
210
@@ -213,9 +213,9 @@ def _as_card_items(
213
213
raise ValueError ("`TagAttrs` are not allowed in `_as_card_items(*children=)`." )
214
214
215
215
if not callable (wrapper ):
216
- ret : list [CardItem ] = []
216
+ ret : list [TagChild ] = []
217
217
for child in children_vals :
218
- if isinstance (child , CardItem ):
218
+ if is_card_item (child ):
219
219
ret .append (child )
220
220
else :
221
221
ret .append (CardItem (child ))
@@ -225,7 +225,7 @@ def _as_card_items(
225
225
# children that are not, should be wrapped in card_body(). Consecutive children
226
226
# that are not card_item, should be wrapped in a single card_body().
227
227
state = "asis" # "wrap" | "asis"
228
- new_children : list [CardItem ] = []
228
+ new_children : list [TagChild ] = []
229
229
children_to_wrap : list [TagChild ] = []
230
230
231
231
def wrap_children ():
@@ -235,7 +235,7 @@ def wrap_children():
235
235
children_to_wrap = []
236
236
237
237
for child in children_vals :
238
- if isinstance (child , CardItem ):
238
+ if is_card_item (child ):
239
239
if state == "wrap" :
240
240
wrap_children ()
241
241
state = "asis"
@@ -250,13 +250,18 @@ def wrap_children():
250
250
return new_children
251
251
252
252
253
- def _wrap_children_in_card (
254
- * children : TagChild | CardItem | None , # `TagAttrs` are not allowed here
255
- wrapper : WrapperCallable | None ,
256
- ) -> list [TagChild ]:
257
- card_items = _as_card_items (* children , wrapper = wrapper )
258
- tag_children = [card_item .resolve () for card_item in card_items ]
259
- return tag_children
253
+ def is_card_item (x : object ) -> bool :
254
+ if isinstance (x , CardItem ):
255
+ return True
256
+
257
+ # This is for express' RecallContextManager[CardItem]
258
+ # which we want to treat like a CardItem.
259
+ fn = getattr (x , "fn" , None )
260
+ if callable (fn ):
261
+ ann = getattr (fn , "__annotations__" , {})
262
+ return ann .get ("return" , None ) == "CardItem"
263
+
264
+ return False
260
265
261
266
262
267
# TODO-maindocs; @add_example()
@@ -394,17 +399,6 @@ def __init__(
394
399
):
395
400
self ._item = item
396
401
397
- def resolve (self ) -> TagChild :
398
- """
399
- Resolves an object with the `CardItem` class by returning the `item` provided at initialization.
400
-
401
- Returns
402
- -------
403
- :
404
- The `item` provided at initialization.
405
- """
406
- return self ._item
407
-
408
402
def tagify (self ) -> TagList :
409
403
"""
410
404
Tagify the `item`
@@ -414,7 +408,7 @@ def tagify(self) -> TagList:
414
408
:
415
409
A tagified :class:`~htmltools.TagList` object.
416
410
"""
417
- return TagList (self .resolve () ).tagify ()
411
+ return TagList (self ._item ).tagify ()
418
412
419
413
420
414
@add_example ()
0 commit comments