(
meth: Callable[..., _AbstractLoad],
keys: Tuple[_AttrType, ...],
chained: bool,
kw: Any,
)
| 2294 | |
| 2295 | |
| 2296 | def _generate_from_keys( |
| 2297 | meth: Callable[..., _AbstractLoad], |
| 2298 | keys: Tuple[_AttrType, ...], |
| 2299 | chained: bool, |
| 2300 | kw: Any, |
| 2301 | ) -> _AbstractLoad: |
| 2302 | lead_element: Optional[_AbstractLoad] = None |
| 2303 | |
| 2304 | attr: Any |
| 2305 | for is_default, _keys in (True, keys[0:-1]), (False, keys[-1:]): |
| 2306 | for attr in _keys: |
| 2307 | if isinstance(attr, str): |
| 2308 | if attr.startswith("." + _WILDCARD_TOKEN): |
| 2309 | util.warn_deprecated( |
| 2310 | "The undocumented `.{WILDCARD}` format is " |
| 2311 | "deprecated " |
| 2312 | "and will be removed in a future version as " |
| 2313 | "it is " |
| 2314 | "believed to be unused. " |
| 2315 | "If you have been using this functionality, " |
| 2316 | "please " |
| 2317 | "comment on Issue #4390 on the SQLAlchemy project " |
| 2318 | "tracker.", |
| 2319 | version="1.4", |
| 2320 | ) |
| 2321 | attr = attr[1:] |
| 2322 | |
| 2323 | if attr == _WILDCARD_TOKEN: |
| 2324 | if is_default: |
| 2325 | raise sa_exc.ArgumentError( |
| 2326 | "Wildcard token cannot be followed by " |
| 2327 | "another entity", |
| 2328 | ) |
| 2329 | |
| 2330 | if lead_element is None: |
| 2331 | lead_element = _WildcardLoad() |
| 2332 | |
| 2333 | lead_element = meth(lead_element, _DEFAULT_TOKEN, **kw) |
| 2334 | |
| 2335 | else: |
| 2336 | raise sa_exc.ArgumentError( |
| 2337 | "Strings are not accepted for attribute names in " |
| 2338 | "loader options; please use class-bound " |
| 2339 | "attributes directly.", |
| 2340 | ) |
| 2341 | else: |
| 2342 | if lead_element is None: |
| 2343 | _, lead_entity, _ = _parse_attr_argument(attr) |
| 2344 | lead_element = Load(lead_entity) |
| 2345 | |
| 2346 | if is_default: |
| 2347 | if not chained: |
| 2348 | lead_element = lead_element.defaultload(attr) |
| 2349 | else: |
| 2350 | lead_element = meth( |
| 2351 | lead_element, attr, _is_chain=True, **kw |
| 2352 | ) |
| 2353 | else: |
no test coverage detected