From 5e7b9d5506ff0f2891e10248255394592cc779b9 2022-12-09 18:19:17 From: Jason Grout Date: 2022-12-09 18:19:17 Subject: [PATCH] Lint --- diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index 3a80f05..1227fd0 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -554,44 +554,57 @@ class Inspector(Colorable): def format_mime(self, bundle): """Format a mimebundle being created by _make_info_unformatted into a real mimebundle""" # Format text/plain mimetype - if isinstance(bundle['text/plain'], (list, tuple)): + if isinstance(bundle["text/plain"], (list, tuple)): # bundle['text/plain'] is a list of (head, formatted body) pairs lines = [] - _len = max(len(h) for h,_ in bundle['text/plain']) + _len = max(len(h) for h, _ in bundle["text/plain"]) - for head, body in bundle['text/plain']: - body = body.strip('\n') - delim = '\n' if '\n' in body else ' ' - lines.append(f"{self.__head(head+':')}{(_len - len(head))*' '}{delim}{body}") + for head, body in bundle["text/plain"]: + body = body.strip("\n") + delim = "\n" if "\n" in body else " " + lines.append( + f"{self.__head(head+':')}{(_len - len(head))*' '}{delim}{body}" + ) - bundle['text/plain'] = '\n'.join(lines) + bundle["text/plain"] = "\n".join(lines) # Format the text/html mimetype - if isinstance(bundle['text/html'], (list, tuple)): + if isinstance(bundle["text/html"], (list, tuple)): # bundle['text/html'] is a list of (head, formatted body) pairs - bundle['text/html'] = '\n'.join((f'

{head}

\n{body}' for (head,body) in bundle['text/html'])) + bundle["text/html"] = "\n".join( + (f"

{head}

\n{body}" for (head, body) in bundle["text/html"]) + ) return bundle - def _append_info_field(self, bundle, title:str, key:str, info, omit_sections, formatter): + def _append_info_field( + self, bundle, title: str, key: str, info, omit_sections, formatter + ): """Append an info value to the unformatted mimebundle being constructed by _make_info_unformatted""" if title in omit_sections or key in omit_sections: return field = info[key] if field is not None: formatted_field = self._mime_format(field, formatter) - bundle['text/plain'].append((title, formatted_field['text/plain'])) - bundle['text/html'].append((title, formatted_field['text/html'])) + bundle["text/plain"].append((title, formatted_field["text/plain"])) + bundle["text/html"].append((title, formatted_field["text/html"])) def _make_info_unformatted(self, info, formatter, detail_level, omit_sections): """Assemble the mimebundle as unformatted lists of information""" bundle = { - 'text/plain': [], - 'text/html': [], + "text/plain": [], + "text/html": [], } # A convenience function to simplify calls below - def append_field(bundle, title:str, key:str, formatter=None): - self._append_info_field(bundle, title=title, key=key, info=info, omit_sections=omit_sections, formatter=formatter) + def append_field(bundle, title: str, key: str, formatter=None): + self._append_info_field( + bundle, + title=title, + key=key, + info=info, + omit_sections=omit_sections, + formatter=formatter, + ) def code_formatter(text): return { @@ -599,54 +612,54 @@ class Inspector(Colorable): 'text/html': pylight(text) } - if info['isalias']: - append_field(bundle, 'Repr', 'string_form') + if info["isalias"]: + append_field(bundle, "Repr", "string_form") elif info['ismagic']: if detail_level > 0: - append_field(bundle, 'Source', 'source', code_formatter) + append_field(bundle, "Source", "source", code_formatter) else: - append_field(bundle, 'Docstring', 'docstring', formatter) - append_field(bundle, 'File', 'file') + append_field(bundle, "Docstring", "docstring", formatter) + append_field(bundle, "File", "file") elif info['isclass'] or is_simple_callable(obj): # Functions, methods, classes - append_field(bundle, 'Signature', 'definition', code_formatter) - append_field(bundle, 'Init signature', 'init_definition', code_formatter) - append_field(bundle, 'Docstring', 'docstring', formatter) - if detail_level > 0 and info['source']: - append_field(bundle, 'Source', 'source', code_formatter) + append_field(bundle, "Signature", "definition", code_formatter) + append_field(bundle, "Init signature", "init_definition", code_formatter) + append_field(bundle, "Docstring", "docstring", formatter) + if detail_level > 0 and info["source"]: + append_field(bundle, "Source", "source", code_formatter) else: - append_field(bundle, 'Init docstring', 'init_docstring', formatter) + append_field(bundle, "Init docstring", "init_docstring", formatter) - append_field(bundle, 'File', 'file') - append_field(bundle, 'Type', 'type_name') - append_field(bundle, 'Subclasses', 'subclasses') + append_field(bundle, "File", "file") + append_field(bundle, "Type", "type_name") + append_field(bundle, "Subclasses", "subclasses") else: # General Python objects - append_field(bundle, 'Signature', 'definition', code_formatter) - append_field(bundle, 'Call signature', 'call_def', code_formatter) - append_field(bundle, 'Type', 'type_name') - append_field(bundle, 'String form', 'string_form') + append_field(bundle, "Signature", "definition", code_formatter) + append_field(bundle, "Call signature", "call_def", code_formatter) + append_field(bundle, "Type", "type_name") + append_field(bundle, "String form", "string_form") # Namespace - if info['namespace'] != 'Interactive': - append_field(bundle, 'Namespace', 'namespace') + if info["namespace"] != "Interactive": + append_field(bundle, "Namespace", "namespace") - append_field(bundle, 'Length', 'length') - append_field(bundle, 'File', 'file') + append_field(bundle, "Length", "length") + append_field(bundle, "File", "file") # Source or docstring, depending on detail level and whether # source found. - if detail_level > 0 and info['source']: - append_field(bundle, 'Source', 'source', code_formatter) + if detail_level > 0 and info["source"]: + append_field(bundle, "Source", "source", code_formatter) else: - append_field(bundle, 'Docstring', 'docstring', formatter) + append_field(bundle, "Docstring", "docstring", formatter) - append_field(bundle, 'Class docstring', 'class_docstring', formatter) - append_field(bundle, 'Init docstring', 'init_docstring', formatter) - append_field(bundle, 'Call docstring', 'call_docstring', formatter) + append_field(bundle, "Class docstring", "class_docstring", formatter) + append_field(bundle, "Init docstring", "init_docstring", formatter) + append_field(bundle, "Call docstring", "call_docstring", formatter) return bundle @@ -671,7 +684,9 @@ class Inspector(Colorable): """ info = self.info(obj, oname=oname, info=info, detail_level=detail_level) - bundle = self._make_info_unformatted(info, formatter, detail_level=detail_level, omit_sections=omit_sections) + bundle = self._make_info_unformatted( + info, formatter, detail_level=detail_level, omit_sections=omit_sections + ) return self.format_mime(bundle) def pinfo(