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

Method _populate_completion

bpython/urwid.py:753–853  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

751 )
752
753 def _populate_completion(self):
754 widget_list = self.tooltip.body
755 while widget_list:
756 widget_list.pop()
757 # This is just me flailing around wildly. TODO: actually write.
758 if self.complete():
759 if self.funcprops:
760 # This is mostly just stolen from the cli module.
761 func_name = self.funcprops.func
762 args = self.funcprops.argspec.args
763 is_bound = self.funcprops.is_bound_method
764 in_arg = self.arg_pos
765 varargs = self.funcprops.argspec.varargs
766 varkw = self.funcprops.argspec.varkwargs
767 defaults = self.funcprops.argspec.defaults
768 kwonly = self.funcprops.argspec.kwonly
769 kwonly_defaults = self.funcprops.argspec.kwonly_defaults or {}
770 markup = [("bold name", func_name), ("name", ": (")]
771
772 # the isinstance checks if we're in a positional arg
773 # (instead of a keyword arg), I think
774 if is_bound and isinstance(in_arg, int):
775 in_arg += 1
776
777 # bpython.cli checks if this goes off the edge and
778 # does clever wrapping. I do not (yet).
779 for k, i in enumerate(args):
780 if defaults and k + 1 > len(args) - len(defaults):
781 kw = repr(defaults[k - (len(args) - len(defaults))])
782 else:
783 kw = None
784
785 if not k and str(i) == "self":
786 color = "name"
787 else:
788 color = "token"
789
790 if k == in_arg or i == in_arg:
791 color = "bold " + color
792
793 markup.append((color, str(i)))
794 if kw is not None:
795 markup.extend([("punctuation", "="), ("token", kw)])
796 if k != len(args) - 1:
797 markup.append(("punctuation", ", "))
798
799 if varargs:
800 if args:
801 markup.append(("punctuation", ", "))
802 markup.append(("token", "*" + varargs))
803
804 if kwonly:
805 if not varargs:
806 if args:
807 markup.append(("punctuation", ", "))
808 markup.append(("punctuation", "*"))
809 for arg in kwonly:
810 if arg == in_arg:

Callers 1

on_input_changeMethod · 0.95

Calls 2

appendMethod · 0.80
completeMethod · 0.45

Tested by

no test coverage detected