MCPcopy Create free account
hub / github.com/bpython/bpython / FilenameCompletion

Class FilenameCompletion

bpython/autocomplete.py:349–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347
348
349class FilenameCompletion(BaseCompletionType):
350 def __init__(self, mode: AutocompleteModes = AutocompleteModes.SIMPLE):
351 super().__init__(False, mode)
352
353 def matches(
354 self, cursor_offset: int, line: str, **kwargs: Any
355 ) -> set[str] | None:
356 cs = lineparts.current_string(cursor_offset, line)
357 if cs is None:
358 return None
359 matches = set()
360 username = cs.word.split(os.path.sep, 1)[0]
361 user_dir = os.path.expanduser(username)
362 for filename in _safe_glob(os.path.expanduser(cs.word)):
363 if os.path.isdir(filename):
364 filename += os.path.sep
365 if cs.word.startswith("~"):
366 filename = username + filename[len(user_dir) :]
367 matches.add(filename)
368 return matches
369
370 def locate(self, cursor_offset: int, line: str) -> LinePart | None:
371 return lineparts.current_string(cursor_offset, line)
372
373 def format(self, filename: str) -> str:
374 if os.sep in filename[:-1]:
375 return filename[filename.rindex(os.sep, 0, -1) + 1 :]
376 else:
377 return filename
378
379
380class AttrCompletion(BaseCompletionType):

Callers 1

get_default_completerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected