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
| 44 | |
| 45 | @cython.cclass |
| 46 | class 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"] |
no outgoing calls