MCPcopy Index your code
hub / github.com/bpython/bpython / complete

Method complete

bpython/importcompletion.py:133–167  ·  view source on GitHub ↗

Construct a full list of possibly completions for imports.

(self, cursor_offset: int, line: str)

Source from the content-addressed store, hash-verified

131 return self.attr_matches(name, only_modules=True)
132
133 def complete(self, cursor_offset: int, line: str) -> set[str] | None:
134 """Construct a full list of possibly completions for imports."""
135 tokens = line.split()
136 if "from" not in tokens and "import" not in tokens:
137 return None
138
139 result = current_word(cursor_offset, line)
140 if result is None:
141 return None
142
143 from_import_from = current_from_import_from(cursor_offset, line)
144 if from_import_from is not None:
145 import_import = current_from_import_import(cursor_offset, line)
146 if import_import is not None:
147 # `from a import <b|>` completion
148 matches = self.module_matches(
149 import_import.word, from_import_from.word
150 )
151 matches.update(
152 self.attr_matches(import_import.word, from_import_from.word)
153 )
154 else:
155 # `from <a|>` completion
156 matches = self.module_attr_matches(from_import_from.word)
157 matches.update(self.module_matches(from_import_from.word))
158 return matches
159
160 cur_import = current_import(cursor_offset, line)
161 if cur_import is not None:
162 # `import <a|>` completion
163 matches = self.module_matches(cur_import.word)
164 matches.update(self.module_attr_matches(cur_import.word))
165 return matches
166 else:
167 return None
168
169 def find_modules(self, path: Path) -> Generator[str | None, None, None]:
170 """Find all modules (and packages) for a given directory."""

Callers 1

test_issue_847Method · 0.95

Calls 8

module_matchesMethod · 0.95
attr_matchesMethod · 0.95
module_attr_matchesMethod · 0.95
current_wordFunction · 0.85
current_from_import_fromFunction · 0.85
current_importFunction · 0.85
updateMethod · 0.80

Tested by 1

test_issue_847Method · 0.76