a quick cache key generator used by reflection.flexi_cache.
(
tokens: Tuple[Any, ...],
traverse_args: Iterable[Tuple[str, InternalTraversal]],
args: Iterable[Any],
)
| 565 | |
| 566 | |
| 567 | def _ad_hoc_cache_key_from_args( |
| 568 | tokens: Tuple[Any, ...], |
| 569 | traverse_args: Iterable[Tuple[str, InternalTraversal]], |
| 570 | args: Iterable[Any], |
| 571 | ) -> Tuple[Any, ...]: |
| 572 | """a quick cache key generator used by reflection.flexi_cache.""" |
| 573 | bindparams: List[BindParameter[Any]] = [] |
| 574 | |
| 575 | _anon_map = anon_map() |
| 576 | |
| 577 | tup = tokens |
| 578 | |
| 579 | for (attrname, sym), arg in zip(traverse_args, args): |
| 580 | key = sym.name |
| 581 | visit_key = key.replace("dp_", "visit_") |
| 582 | |
| 583 | if arg is None: |
| 584 | tup += (attrname, None) |
| 585 | continue |
| 586 | |
| 587 | meth = getattr(_cache_key_traversal_visitor, visit_key) |
| 588 | if meth is CACHE_IN_PLACE: |
| 589 | tup += (attrname, arg) |
| 590 | elif meth in ( |
| 591 | CALL_GEN_CACHE_KEY, |
| 592 | STATIC_CACHE_KEY, |
| 593 | ANON_NAME, |
| 594 | PROPAGATE_ATTRS, |
| 595 | ): |
| 596 | raise NotImplementedError( |
| 597 | f"Haven't implemented symbol {meth} for ad-hoc key from args" |
| 598 | ) |
| 599 | else: |
| 600 | tup += meth(attrname, arg, None, _anon_map, bindparams) |
| 601 | return tup |
| 602 | |
| 603 | |
| 604 | class _CacheKeyTraversal(HasTraversalDispatch): |