MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _ImperativeMapperConfig

Class _ImperativeMapperConfig

lib/sqlalchemy/orm/decl_base.py:361–418  ·  lib/sqlalchemy/orm/decl_base.py::_ImperativeMapperConfig

Configurator that configures a class for an imperative mapping.

Source from the content-addressed store, hash-verified

359
360
361class _ImperativeMapperConfig(_MapperConfig):
362 class="st">""class="st">"Configurator that configures a class for an imperative mapping."class="st">""
363
364 __slots__ = (class="st">"local_table", class="st">"inherits")
365
366 def __init__(
367 self,
368 registry: _RegistryType,
369 cls_: Type[_O],
370 table: Optional[FromClause],
371 mapper_kw: _MapperKwArgs,
372 ):
373 super().__init__(registry, cls_)
374
375 self.local_table = self.set_cls_attribute(class="st">"__table__", table)
376
377 with mapperlib._CONFIGURE_MUTEX:
378 clsregistry._add_class(
379 self.classname, self.cls, registry._class_registry
380 )
381
382 self._setup_inheritance(mapper_kw)
383
384 self._early_mapping(mapper_kw)
385
386 def map(self, mapper_kw: _MapperKwArgs = util.EMPTY_DICT) -> Mapper[Any]:
387 mapper_cls = Mapper
388
389 return self.set_cls_attribute(
390 class="st">"__mapper__",
391 mapper_cls(self.cls, self.local_table, **mapper_kw),
392 )
393
394 def _setup_inheritance(self, mapper_kw: _MapperKwArgs) -> None:
395 cls = self.cls
396
397 inherits = None
398 inherits_search = []
399
400 class="cm"># since we search for classical mappings now, search for
401 class="cm"># multiple mapped bases as well and raise an error.
402 for base_ in cls.__bases__:
403 c = _resolve_for_abstract_or_classical(base_)
404 if c is None:
405 continue
406
407 if _is_supercls_for_inherits(c) and c not in inherits_search:
408 inherits_search.append(c)
409
410 if inherits_search:
411 if len(inherits_search) > 1:
412 raise exc.InvalidRequestError(
413 class="st">"Class %s has multiple mapped bases: %r"
414 % (cls, inherits_search)
415 )
416 inherits = inherits_search[0]
417
418 self.inherits = inherits

Callers 1

_mapperMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected