MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / __init__

Method __init__

lib/sqlalchemy/sql/elements.py:3339–3388  ·  view source on GitHub ↗
(
        self,
        *whens: Union[
            typing_Tuple[_ColumnExpressionArgument[bool], Any],
            Mapping[Any, Any],
        ],
        value: Optional[Any] = None,
        else_: Optional[Any] = None,
    )

Source from the content-addressed store, hash-verified

3337 value: Optional[ColumnElement[Any]]
3338
3339 def __init__(
3340 self,
3341 *whens: Union[
3342 typing_Tuple[_ColumnExpressionArgument[bool], Any],
3343 Mapping[Any, Any],
3344 ],
3345 value: Optional[Any] = None,
3346 else_: Optional[Any] = None,
3347 ):
3348 new_whens: Iterable[Any] = coercions._expression_collection_was_a_list(
3349 "whens", "case", whens
3350 )
3351 try:
3352 new_whens = util.dictlike_iteritems(new_whens)
3353 except TypeError:
3354 pass
3355
3356 self.whens = [
3357 (
3358 coercions.expect(
3359 roles.ExpressionElementRole,
3360 c,
3361 apply_propagate_attrs=self,
3362 ).self_group(),
3363 coercions.expect(roles.ExpressionElementRole, r),
3364 )
3365 for (c, r) in new_whens
3366 ]
3367
3368 if value is None:
3369 self.value = None
3370 else:
3371 self.value = coercions.expect(roles.ExpressionElementRole, value)
3372
3373 if else_ is not None:
3374 self.else_ = coercions.expect(roles.ExpressionElementRole, else_)
3375 else:
3376 self.else_ = None
3377
3378 type_ = next(
3379 (
3380 then.type
3381 # Iterate `whens` in reverse to match previous behaviour
3382 # where type of final element took priority
3383 for *_, then in reversed(self.whens)
3384 if not then.type._isnull
3385 ),
3386 self.else_.type if self.else_ is not None else type_api.NULLTYPE,
3387 )
3388 self.type = cast(_T, type_)
3389
3390 @util.ro_non_memoized_property
3391 def _from_objects(self) -> List[FromClause]:

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 2

castFunction · 0.85
self_groupMethod · 0.45

Tested by

no test coverage detected