def get_signature(self, content): """Get signature from inspect reply content""" data = content.get('data', {}) text = data.get('text/plain', '') if text: text = ANSI_OR_SPECIAL_PATTERN.sub('', text) self._control.current_prompt_pos = self._prompt_pos line = self._control.get_current_line_to_cursor() name = line[:-1].split('(')[-1] # Take last token after a ( name = name.split('.')[-1] # Then take last token after a . # Clean name from invalid chars try: name = self.clean_invalid_var_chars(name).split('_')[-1] except: pass argspec = getargspecfromtext(text) if argspec: # This covers cases like np.abs, whose docstring is # the same as np.absolute and because of that a proper # signature can't be obtained correctly signature = name + argspec else: signature = getsignaturefromtext(text, name) # Remove docstring for uniformity with editor signature = signature.split('Docstring:')[0] return signature else: return ''
def get_signature(self, content): """Get signature from inspect reply content""" data = content.get('data', {}) text = data.get('text/plain', '') if text: text = ANSI_OR_SPECIAL_PATTERN.sub('', text) self._control.current_prompt_pos = self._prompt_pos line = self._control.get_current_line_to_cursor() name = line[:-1].split('(')[-1] # Take last token after a ( name = name.split('.')[-1] # Then take last token after a . # Clean name from invalid chars try: name = self.clean_invalid_var_chars(name).split('_')[-1] except: pass argspec = getargspecfromtext(text) if argspec: # This covers cases like np.abs, whose docstring is # the same as np.absolute and because of that a proper # signature can't be obtained correctly signature = name + argspec else: signature = getsignaturefromtext(text, name) # Remove docstring for uniformity with editor signature = signature.split('Docstring:')[0] return signature else: return ''
def show_object_info(self, text, call=False, force=False): """Show signature calltip and/or docstring in the Help plugin""" text = to_text_string(text) # Show docstring help_enabled = self.help_enabled or force if force and self.help is not None: self.help.dockwidget.setVisible(True) self.help.dockwidget.raise_() if help_enabled and (self.help is not None) and \ (self.help.dockwidget.isVisible()): # Help widget exists and is visible if hasattr(self, 'get_doc'): self.help.set_shell(self) else: self.help.set_shell(self.parent()) self.help.set_object_text(text, ignore_unknown=False) self.setFocus() # if help was not at top level, raising it to # top will automatically give it focus because of # the visibility_changed signal, so we must give # focus back to shell # Show calltip if call and self.calltips: # Display argument list if this is a function call iscallable = self.iscallable(text) if iscallable is not None: if iscallable: arglist = self.get_arglist(text) name = text.split('.')[-1] argspec = signature = '' if isinstance(arglist, bool): arglist = [] if arglist: argspec = '(' + ''.join(arglist) + ')' else: doc = self.get__doc__(text) if doc is not None: # This covers cases like np.abs, whose docstring is # the same as np.absolute and because of that a # proper signature can't be obtained correctly argspec = getargspecfromtext(doc) if not argspec: signature = getsignaturefromtext(doc, name) if argspec or signature: if argspec: tiptext = name + argspec else: tiptext = signature self.show_calltip(_("Arguments"), tiptext, signature=True, color='#2D62FF')
def _get_signature(self, name, text): """Get signature from text using a given function name.""" signature = '' argspec = getargspecfromtext(text) if argspec: # This covers cases like np.abs, whose docstring is # the same as np.absolute and because of that a proper # signature can't be obtained correctly signature = name + argspec else: signature = getsignaturefromtext(text, name) return signature
def show_object_info(self, text, call=False, force=False): """Show signature calltip and/or docstring in the Help plugin""" text = to_text_string(text) # Show docstring help_enabled = self.help_enabled or force if force and self.help is not None: self.help.dockwidget.setVisible(True) self.help.dockwidget.raise_() if help_enabled and (self.help is not None) and \ (self.help.dockwidget.isVisible()): # Help widget exists and is visible if hasattr(self, 'get_doc'): self.help.set_shell(self) else: self.help.set_shell(self.parent()) self.help.set_object_text(text, ignore_unknown=False) self.setFocus() # if help was not at top level, raising it to # top will automatically give it focus because of # the visibility_changed signal, so we must give # focus back to shell # Show calltip if call and self.calltips: # Display argument list if this is a function call iscallable = self.iscallable(text) if iscallable is not None: if iscallable: arglist = self.get_arglist(text) name = text.split('.')[-1] argspec = signature = '' if isinstance(arglist, bool): arglist = [] if arglist: argspec = '(' + ''.join(arglist) + ')' else: doc = self.get__doc__(text) if doc is not None: # This covers cases like np.abs, whose docstring is # the same as np.absolute and because of that a # proper signature can't be obtained correctly argspec = getargspecfromtext(doc) if not argspec: signature = getsignaturefromtext(doc, name) if argspec or signature: if argspec: tiptext = name + argspec else: tiptext = signature self.show_calltip(_("Arguments"), tiptext, signature=True, color='#2D62FF')
def handle_info(self, cts, doc_text, source_code, offset): obj_fullname = '' calltip = '' argspec = '' note = '' if cts: cts = cts.replace('.__init__', '') parpos = cts.find('(') if parpos: obj_fullname = cts[:parpos] obj_name = obj_fullname.split('.')[-1] cts = cts.replace(obj_fullname, obj_name) calltip = cts if ('()' in cts) or ('(...)' in cts): # Either inspected object has no argument, or it's # a builtin or an extension -- in this last case # the following attempt may succeed: calltip = getsignaturefromtext(doc_text, obj_name) if not obj_fullname: obj_fullname = sourcecode.get_primary_at(source_code, offset) if obj_fullname and not obj_fullname.startswith('self.'): # doc_text was generated by utils.dochelpers.getdoc if type(doc_text) is dict: obj_fullname = doc_text['name'] or obj_fullname argspec = doc_text['argspec'] note = doc_text['note'] doc_text = doc_text['docstring'] elif calltip: argspec_st = calltip.find('(') argspec = calltip[argspec_st:] module_end = obj_fullname.rfind('.') module = obj_fullname[:module_end] note = 'Present in %s module' % module if not doc_text and not calltip: return default_info_response() return dict(name=obj_fullname, argspec=argspec, note=note, docstring=doc_text, calltip=calltip)
def get_info(self, info): """ Find the calltip and docs Returns a dict like the following: {'note': 'Function of numpy.core.numeric...', 'argspec': "(shape, dtype=None, order='C')' 'docstring': 'Return an array of given...' 'name': 'ones', 'calltip': 'ones(shape, dtype=None, order='C')'} """ call_def = self.get_jedi_object('goto_definitions', info) for cd in call_def: docstring = cd.docstring() if docstring and not docstring.rstrip().endswith(')'): call_def = cd break else: try: call_def = call_def[0] docstring = call_def.docstring() except IndexError: return default_info_response() name = call_def.name if name is None: return default_info_response() if call_def.module_path: mod_name = get_parent_until(call_def.module_path) else: mod_name = None if not mod_name: mod_name = call_def.module_name if docstring.startswith(name + '('): calltip = getsignaturefromtext(docstring, name) argspec = calltip[calltip.find('('):] docstring = docstring[docstring.find(')') + 3:] elif docstring and '(' in docstring.splitlines()[0]: calltip = docstring.splitlines()[0] name = docstring.split('(')[0] docstring = docstring[docstring.find(')') + 3:] argspec = calltip[calltip.find('('):] else: calltip = name + '(...)' argspec = '()' if call_def.type == 'module': note = 'Module %s' % mod_name argspec = '' calltip = name elif call_def.type == 'class': note = 'Class in %s module' % mod_name elif docstring.startswith('%s(self' % name): class_name = call_def.full_name.split('.')[-2] note = 'Method of %s class in %s module' % ( class_name.capitalize(), mod_name) else: note = '%s in %s module' % (call_def.type.capitalize(), mod_name) argspec = argspec.replace(' = ', '=') calltip = calltip.replace(' = ', '=') debug_print(call_def.name) doc_info = dict(name=name, argspec=argspec, note=note, docstring=docstring, calltip=calltip) return doc_info