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

Method __init__

lib/sqlalchemy/orm/decl_api.py:1160–1226  ·  view source on GitHub ↗

r"""Construct a new :class:`_orm.registry` :param metadata: An optional :class:`_schema.MetaData` instance. All :class:`_schema.Table` objects generated using declarative table mapping will make use of this :class:`_schema.MetaData` collection. If t

(
        self,
        *,
        metadata: Optional[MetaData] = None,
        class_registry: Optional[clsregistry._ClsRegistryType] = None,
        type_annotation_map: Optional[_TypeAnnotationMapType] = None,
        constructor: Callable[..., None] = _declarative_constructor,
    )

Source from the content-addressed store, hash-verified

1158 _new_mappers: bool
1159
1160 def __init__(
1161 self,
1162 *,
1163 metadata: Optional[MetaData] = None,
1164 class_registry: Optional[clsregistry._ClsRegistryType] = None,
1165 type_annotation_map: Optional[_TypeAnnotationMapType] = None,
1166 constructor: Callable[..., None] = _declarative_constructor,
1167 ):
1168 r"""Construct a new :class:`_orm.registry`
1169
1170 :param metadata:
1171 An optional :class:`_schema.MetaData` instance. All
1172 :class:`_schema.Table` objects generated using declarative
1173 table mapping will make use of this :class:`_schema.MetaData`
1174 collection. If this argument is left at its default of ``None``,
1175 a blank :class:`_schema.MetaData` collection is created.
1176
1177 :param constructor:
1178 Specify the implementation for the ``__init__`` function on a mapped
1179 class that has no ``__init__`` of its own. Defaults to an
1180 implementation that assigns \**kwargs for declared
1181 fields and relationships to an instance. If ``None`` is supplied,
1182 no __init__ will be provided and construction will fall back to
1183 cls.__init__ by way of the normal Python semantics.
1184
1185 :param class_registry: optional dictionary that will serve as the
1186 registry of class names-> mapped classes when string names
1187 are used to identify classes inside of :func:`_orm.relationship`
1188 and others. Allows two or more declarative base classes
1189 to share the same registry of class names for simplified
1190 inter-base relationships.
1191
1192 :param type_annotation_map: optional dictionary of Python types to
1193 SQLAlchemy :class:`_types.TypeEngine` classes or instances.
1194 The provided dict will update the default type mapping. This
1195 is used exclusively by the :class:`_orm.MappedColumn` construct
1196 to produce column types based on annotations within the
1197 :class:`_orm.Mapped` type.
1198
1199 .. versionadded:: 2.0
1200
1201 .. seealso::
1202
1203 :ref:`orm_declarative_mapped_column_type_map`
1204
1205
1206 """
1207 lcl_metadata = metadata or MetaData()
1208
1209 if class_registry is None:
1210 class_registry = weakref.WeakValueDictionary()
1211
1212 self._class_registry = class_registry
1213 self._managers = weakref.WeakKeyDictionary()
1214 self._non_primary_mappers = weakref.WeakKeyDictionary()
1215 self.metadata = lcl_metadata
1216 self.constructor = constructor
1217 self.type_annotation_map = {}

Callers 1

__init__Method · 0.45

Calls 2

MetaDataClass · 0.85

Tested by

no test coverage detected