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