MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / prefix_anon_map

Class prefix_anon_map

lib/sqlalchemy/sql/_util_cy.py:46–69  ·  view source on GitHub ↗

A map that creates new keys for missing key access. Considers keys of the form "<ident> <name>" to produce new symbols "<name>_<index>", where "index" is an incrementing integer corresponding to <name>. Inlines the approach taken by :class:`sqlalchemy.util.PopulateDict` which i

Source from the content-addressed store, hash-verified

44
45@cython.cclass
46class prefix_anon_map(Dict[str, str]):
47 """A map that creates new keys for missing key access.
48
49 Considers keys of the form "<ident> <name>" to produce
50 new symbols "<name>_<index>", where "index" is an incrementing integer
51 corresponding to <name>.
52
53 Inlines the approach taken by :class:`sqlalchemy.util.PopulateDict` which
54 is otherwise usually used for this type of operation.
55
56 """
57
58 def __missing__(self, key: str, /) -> str:
59 derived: str
60 value: str
61 self_dict: dict = self # type: ignore[type-arg]
62
63 derived = key.split(" ", 1)[1]
64
65 anonymous_counter: int = self_dict.get(derived, 1)
66 self_dict[derived] = anonymous_counter + 1
67 value = f"{derived}_{anonymous_counter}"
68 self_dict[key] = value
69 return value
70
71
72_AM_KEY = Union[int, str, "CacheConst"]

Callers 4

_generate_param_dictMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls