MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _set_with_polymorphic

Method _set_with_polymorphic

lib/sqlalchemy/orm/mapper.py:1326–1362  ·  view source on GitHub ↗
(
        self, with_polymorphic: Optional[_WithPolymorphicArg]
    )

Source from the content-addressed store, hash-verified

1324 )
1325
1326 def _set_with_polymorphic(
1327 self, with_polymorphic: Optional[_WithPolymorphicArg]
1328 ) -> None:
1329 if with_polymorphic == "*":
1330 self.with_polymorphic = ("*", None)
1331 elif isinstance(with_polymorphic, (tuple, list)):
1332 if isinstance(with_polymorphic[0], (str, tuple, list)):
1333 self.with_polymorphic = cast(
1334 """Tuple[
1335 Union[
1336 Literal["*"],
1337 Sequence[Union["Mapper[Any]", Type[Any]]],
1338 ],
1339 Optional["FromClause"],
1340 ]""",
1341 with_polymorphic,
1342 )
1343 else:
1344 self.with_polymorphic = (with_polymorphic, None)
1345 elif with_polymorphic is not None:
1346 raise sa_exc.ArgumentError(
1347 f"Invalid setting for with_polymorphic: {with_polymorphic!r}"
1348 )
1349 else:
1350 self.with_polymorphic = None
1351
1352 if self.with_polymorphic and self.with_polymorphic[1] is not None:
1353 self.with_polymorphic = (
1354 self.with_polymorphic[0],
1355 coercions.expect(
1356 roles.FromClauseRole,
1357 self.with_polymorphic[1],
1358 ),
1359 )
1360
1361 if self.configured:
1362 self._expire_memoizations()
1363
1364 def _add_with_polymorphic_subclass(self, mapper):
1365 subcl = mapper.class_

Callers 3

__init__Method · 0.95
__declare_first__Method · 0.80

Calls 2

_expire_memoizationsMethod · 0.95
castFunction · 0.50

Tested by

no test coverage detected