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