diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2022-05-16 02:32:44 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-05-16 02:32:44 +0000 |
commit | 5d080d17464712d33c0215d12513e529d848ee8c (patch) | |
tree | eec56f3138a48f55f2585a64f01b4fd9c14451b7 /lib/sqlalchemy/orm/state.py | |
parent | c4dad3695f4ab9fef3a4cb05893492afbec811f7 (diff) | |
parent | 18a73fb1d1c267842ead5dacd05a49f4344d8b22 (diff) | |
download | sqlalchemy-5d080d17464712d33c0215d12513e529d848ee8c.tar.gz |
Merge "revenge of pep 484" into main
Diffstat (limited to 'lib/sqlalchemy/orm/state.py')
-rw-r--r-- | lib/sqlalchemy/orm/state.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index cb8b1f4aa..af9f48706 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -82,6 +82,22 @@ class _InstanceDictProto(Protocol): ... +class _InstallLoaderCallableProto(Protocol[_O]): + """used at result loading time to install a _LoaderCallable callable + upon a specific InstanceState, which will be used to populate an + attribute when that attribute is accessed. + + Concrete examples are per-instance deferred column loaders and + relationship lazy loaders. + + """ + + def __call__( + self, state: InstanceState[_O], dict_: _InstanceDict, row: Row[Any] + ) -> None: + ... + + @inspection._self_inspects class InstanceState(interfaces.InspectionAttrInfo, Generic[_O]): """tracks state information at the instance level. @@ -658,7 +674,7 @@ class InstanceState(interfaces.InspectionAttrInfo, Generic[_O]): @classmethod def _instance_level_callable_processor( cls, manager: ClassManager[_O], fn: _LoaderCallable, key: Any - ) -> Callable[[InstanceState[_O], _InstanceDict, Row[Any]], None]: + ) -> _InstallLoaderCallableProto[_O]: impl = manager[key].impl if is_collection_impl(impl): fixed_impl = impl |