From 7fbd4fd01bfc2e87a35ad561c89667cee3c66bf1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Janek=20Nouvertn=C3=A9?= <25355197+provinzkraut@users.noreply.github.com> Date: Sat, 22 Jul 2023 19:22:20 +0200 Subject: [PATCH] fix typing for load_only, defer and undefer. Change the annotations for the attribute(s) parameters to `QueryableAttribute` and `QueryableAttribute | Literal["*"]` for defer and undefer, to accurately reflect the types they accept. Fixes: #10131 --- lib/sqlalchemy/orm/strategy_options.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index d93ec0a273..3a271cc664 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -2319,7 +2319,9 @@ def contains_eager(*keys: _AttrType, **kw: Any) -> _AbstractLoad: @loader_unbound_fn -def load_only(*attrs: _AttrType, raiseload: bool = False) -> _AbstractLoad: +def load_only( + *attrs: QueryableAttribute[Any], raiseload: bool = False +) -> _AbstractLoad: # TODO: attrs against different classes. we likely have to # add some extra state to Load of some kind _, lead_element, _ = _parse_attr_argument(attrs[0]) @@ -2376,7 +2378,9 @@ def defaultload(*keys: _AttrType) -> _AbstractLoad: @loader_unbound_fn def defer( - key: _AttrType, *addl_attrs: _AttrType, raiseload: bool = False + key: Union[QueryableAttribute[Any], Literal["*"]], + *addl_attrs: Union[QueryableAttribute[Any], Literal["*"]], + raiseload: bool = False, ) -> _AbstractLoad: if addl_attrs: util.warn_deprecated( @@ -2395,7 +2399,10 @@ def defer( @loader_unbound_fn -def undefer(key: _AttrType, *addl_attrs: _AttrType) -> _AbstractLoad: +def undefer( + key: Union[QueryableAttribute[Any], Literal["*"]], + *addl_attrs: Union[QueryableAttribute[Any], Literal["*"]], +) -> _AbstractLoad: if addl_attrs: util.warn_deprecated( "The *addl_attrs on orm.undefer is deprecated. Please use " -- 2.47.3