Given a class, return the primary :class:`_orm.Mapper` associated with the key. Raises :exc:`.UnmappedClassError` if no mapping is configured on the given class, or :exc:`.ArgumentError` if a non-class object is passed. Equivalent functionality is available via the :func:`_sa.i
(class_: Type[_O], configure: bool = True)
| 542 | |
| 543 | |
| 544 | def class_mapper(class_: Type[_O], configure: bool = True) -> Mapper[_O]: |
| 545 | """Given a class, return the primary :class:`_orm.Mapper` associated |
| 546 | with the key. |
| 547 | |
| 548 | Raises :exc:`.UnmappedClassError` if no mapping is configured |
| 549 | on the given class, or :exc:`.ArgumentError` if a non-class |
| 550 | object is passed. |
| 551 | |
| 552 | Equivalent functionality is available via the :func:`_sa.inspect` |
| 553 | function as:: |
| 554 | |
| 555 | inspect(some_mapped_class) |
| 556 | |
| 557 | Using the inspection system will raise |
| 558 | :class:`sqlalchemy.exc.NoInspectionAvailable` if the class is not mapped. |
| 559 | |
| 560 | """ |
| 561 | mapper = _inspect_mapped_class(class_, configure=configure) |
| 562 | if mapper is None: |
| 563 | if not isinstance(class_, type): |
| 564 | raise sa_exc.ArgumentError( |
| 565 | "Class object expected, got '%r'." % (class_,) |
| 566 | ) |
| 567 | raise exc.UnmappedClassError(class_) |
| 568 | else: |
| 569 | return mapper |
| 570 | |
| 571 | |
| 572 | class InspectionAttr: |