MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / class_mapper

Function class_mapper

lib/sqlalchemy/orm/base.py:540–565  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

538
539
540def 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
568class InspectionAttr:

Callers 15

test_mapperMethod · 0.90
_fixtureMethod · 0.90
test_basicMethod · 0.90
assert_instrumentedMethod · 0.90
test_class_mapperMethod · 0.90
test_propertyMethod · 0.90
test_insp_column_propMethod · 0.90
test_rel_accessorsMethod · 0.90

Calls 1

_inspect_mapped_classFunction · 0.85

Tested by 15

test_mapperMethod · 0.72
_fixtureMethod · 0.72
test_basicMethod · 0.72
assert_instrumentedMethod · 0.72
test_class_mapperMethod · 0.72
test_propertyMethod · 0.72
test_insp_column_propMethod · 0.72
test_rel_accessorsMethod · 0.72