manager_of_class = _default_manager_getter = base.manager_of_class
opt_manager_of_class = _default_opt_manager_getter = base.opt_manager_of_class
def register_class(
    class_: Type[_O],
    finalize: bool = True,
    mapper: Optional[Mapper[_O]] = None,
    registry: Optional[_RegistryType] = None,
    declarative_scan: Optional[_MapperConfig] = None,
    expired_attribute_loader: Optional[_ExpiredAttributeLoaderProto] = None,
    init_method: Optional[Callable[..., None]] = None,
) -> ClassManager[_O]:
    """Register class instrumentation.
    Returns the existing or newly created class manager.
    """
    manager = opt_manager_of_class(class_)
    if manager is None:
        manager = _instrumentation_factory.create_manager_for_cls(class_)
    manager._update_state(
        mapper=mapper,
        registry=registry,
        declarative_scan=declarative_scan,
        expired_attribute_loader=expired_attribute_loader,
        init_method=init_method,
        finalize=finalize,
    )
    return manager
def unregister_class(class_):
    """Unregister class instrumentation."""
    _instrumentation_factory.unregister(class_)
def is_instrumented(instance, key):
    """Return True if the given attribute on the given instance is
    instrumented by the attributes package.
    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.
    """
    return manager_of_class(instance.__class__).is_instrumented(
        key, search=True
    )
def _generate_init(class_, class_manager, original_init):
    """Build an __init__ decorator that triggers ClassManager events."""
    # TODO: we should use the ClassManager's notion of the