| 381 | attr_matches_re = LazyReCompile(r"(\w+(\.\w+)*)\.(\w*)") |
| 382 | |
| 383 | def matches( |
| 384 | self, |
| 385 | cursor_offset: int, |
| 386 | line: str, |
| 387 | *, |
| 388 | locals_: dict[str, Any] | None = None, |
| 389 | **kwargs: Any, |
| 390 | ) -> set[str] | None: |
| 391 | r = self.locate(cursor_offset, line) |
| 392 | if r is None: |
| 393 | return None |
| 394 | |
| 395 | if locals_ is None: # TODO add a note about why |
| 396 | locals_ = __main__.__dict__ |
| 397 | |
| 398 | assert "." in r.word |
| 399 | |
| 400 | i = r.word.rfind("[") + 1 |
| 401 | methodtext = r.word[i:] |
| 402 | matches = { |
| 403 | "".join([r.word[:i], m]) |
| 404 | for m in self.attr_matches(methodtext, locals_) |
| 405 | } |
| 406 | |
| 407 | return { |
| 408 | m |
| 409 | for m in matches |
| 410 | if _few_enough_underscores(r.word.split(".")[-1], m.split(".")[-1]) |
| 411 | } |
| 412 | |
| 413 | def locate(self, cursor_offset: int, line: str) -> LinePart | None: |
| 414 | return lineparts.current_dotted_attribute(cursor_offset, line) |