Adapts a matcher function to a locals mapping as required by eval().
| 172 | |
| 173 | |
| 174 | class MatcherAdapter(Mapping[str, bool]): |
| 175 | """Adapts a matcher function to a locals mapping as required by eval().""" |
| 176 | |
| 177 | def __init__(self, matcher: Callable[[str], bool]) -> None: |
| 178 | self.matcher = matcher |
| 179 | |
| 180 | def __getitem__(self, key: str) -> bool: |
| 181 | return self.matcher(key[len(IDENT_PREFIX) :]) |
| 182 | |
| 183 | def __iter__(self) -> Iterator[str]: |
| 184 | raise NotImplementedError() |
| 185 | |
| 186 | def __len__(self) -> int: |
| 187 | raise NotImplementedError() |
| 188 | |
| 189 | |
| 190 | class Expression: |