MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / class_mapper

Function class_mapper

lib/sqlalchemy/orm/base.py:544–569  ·  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

542
543
544def 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
572class 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