A map that creates new keys for missing key access. Considers keys of the form " " to produce new symbols " _ ", where "index" is an incrementing integer corresponding to . Inlines the approach taken by :class:`sqlalchemy.util.PopulateDict` which i
| 20 | |
| 21 | |
| 22 | class prefix_anon_map(Dict[str, str]): |
| 23 | """A map that creates new keys for missing key access. |
| 24 | |
| 25 | Considers keys of the form "<ident> <name>" to produce |
| 26 | new symbols "<name>_<index>", where "index" is an incrementing integer |
| 27 | corresponding to <name>. |
| 28 | |
| 29 | Inlines the approach taken by :class:`sqlalchemy.util.PopulateDict` which |
| 30 | is otherwise usually used for this type of operation. |
| 31 | |
| 32 | """ |
| 33 | |
| 34 | def __missing__(self, key: str) -> str: |
| 35 | ident, derived = key.split(" ", 1) |
| 36 | anonymous_counter = self.get(derived, 1) |
| 37 | self[derived] = anonymous_counter + 1 # type: ignore |
| 38 | value = f"{derived}_{anonymous_counter}" |
| 39 | self[key] = value |
| 40 | return value |
| 41 | |
| 42 | |
| 43 | class cache_anon_map( |
no outgoing calls