MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / count_cache_key_tuples

Function count_cache_key_tuples

lib/sqlalchemy/testing/util.py:500–519  ·  view source on GitHub ↗

given a cache key tuple, counts how many instances of actual tuples are found. used to alert large jumps in cache key complexity.

(tup)

Source from the content-addressed store, hash-verified

498
499
500def count_cache_key_tuples(tup):
501 """given a cache key tuple, counts how many instances of actual
502 tuples are found.
503
504 used to alert large jumps in cache key complexity.
505
506 """
507 stack = [tup]
508
509 sentinel = object()
510 num_elements = 0
511
512 while stack:
513 elem = stack.pop(0)
514 if elem is sentinel:
515 num_elements += 1
516 elif isinstance(elem, tuple):
517 if elem:
518 stack = list(elem) + [sentinel] + stack
519 return num_elements
520
521
522@contextlib.contextmanager

Callers 1

test_cache_key_genMethod · 0.90

Calls 1

popMethod · 0.45

Tested by 1

test_cache_key_genMethod · 0.72