Adapts a matcher function to a locals mapping as required by eval().
| 292 | |
| 293 | |
| 294 | class MatcherAdapter(Mapping[str, MatcherNameAdapter]): |
| 295 | """Adapts a matcher function to a locals mapping as required by eval().""" |
| 296 | |
| 297 | def __init__(self, matcher: ExpressionMatcher) -> None: |
| 298 | self.matcher = matcher |
| 299 | |
| 300 | def __getitem__(self, key: str) -> MatcherNameAdapter: |
| 301 | return MatcherNameAdapter(matcher=self.matcher, name=key[len(IDENT_PREFIX) :]) |
| 302 | |
| 303 | def __iter__(self) -> Iterator[str]: |
| 304 | raise NotImplementedError() |
| 305 | |
| 306 | def __len__(self) -> int: |
| 307 | raise NotImplementedError() |
| 308 | |
| 309 | |
| 310 | @final |