MCPcopy Index your code
hub / github.com/python/cpython / _complete_expression

Method _complete_expression

Lib/pdb.py:1194–1224  ·  view source on GitHub ↗
(self, text, line, begidx, endidx)

Source from the content-addressed store, hash-verified

1192 if bp is not None and str(i).startswith(text)]
1193
1194 def _complete_expression(self, text, line, begidx, endidx):
1195 # Complete an arbitrary expression.
1196 if not self.curframe:
1197 return []
1198 # Collect globals and locals. It is usually not really sensible to also
1199 # complete builtins, and they clutter the namespace quite heavily, so we
1200 # leave them out.
1201 ns = {**self.curframe.f_globals, **self.curframe.f_locals}
1202 if '.' in text:
1203 # Walk an attribute chain up to the last part, similar to what
1204 # rlcompleter does. This will bail if any of the parts are not
1205 # simple attribute access, which is what we want.
1206 dotted = text.split('.')
1207 try:
1208 if dotted[0].startswith('$'):
1209 obj = self.curframe.f_globals['__pdb_convenience_variables'][dotted[0][1:]]
1210 else:
1211 obj = ns[dotted[0]]
1212 for part in dotted[1:-1]:
1213 obj = getattr(obj, part)
1214 except (KeyError, AttributeError):
1215 return []
1216 prefix = '.'.join(dotted[:-1]) + '.'
1217 return [prefix + n for n in dir(obj) if n.startswith(dotted[-1])]
1218 else:
1219 if text.startswith("$"):
1220 # Complete convenience variables
1221 conv_vars = self.curframe.f_globals.get('__pdb_convenience_variables', {})
1222 return [f"${name}" for name in conv_vars if name.startswith(text[1:])]
1223 # Complete a simple name.
1224 return [n for n in ns.keys() if n.startswith(text)]
1225
1226 def _complete_indentation(self, text, line, begidx, endidx):
1227 try:

Callers 2

completenamesMethod · 0.95
_complete_locationMethod · 0.95

Calls 5

splitMethod · 0.45
startswithMethod · 0.45
joinMethod · 0.45
getMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected