##// END OF EJS Templates
cast_unicode code simplification....
Matthias Bussonnier -
Show More
@@ -22,7 +22,7 b' import os'
22 from textwrap import dedent
22 from textwrap import dedent
23 import types
23 import types
24 import io as stdlib_io
24 import io as stdlib_io
25 from itertools import zip_longest
25
26 from typing import Union
26 from typing import Union
27
27
28 # IPython's own
28 # IPython's own
@@ -83,7 +83,7 b" info_fields = ['type_name', 'base_class', 'string_form', 'namespace',"
83
83
84 def object_info(**kw):
84 def object_info(**kw):
85 """Make an object info dict with all fields present."""
85 """Make an object info dict with all fields present."""
86 infodict = dict(zip_longest(info_fields, [None]))
86 infodict = {k:None for k in info_fields}
87 infodict.update(kw)
87 infodict.update(kw)
88 return infodict
88 return infodict
89
89
@@ -512,7 +512,8 b' class Inspector(Colorable):'
512 # 0-offset, so we must adjust.
512 # 0-offset, so we must adjust.
513 page.page(self.format(openpy.read_py_file(ofile, skip_encoding_cookie=False)), lineno - 1)
513 page.page(self.format(openpy.read_py_file(ofile, skip_encoding_cookie=False)), lineno - 1)
514
514
515 def _mime_format(self, text, formatter=None):
515
516 def _mime_format(self, text:str, formatter=None) -> dict:
516 """Return a mime bundle representation of the input text.
517 """Return a mime bundle representation of the input text.
517
518
518 - if `formatter` is None, the returned mime bundle has
519 - if `formatter` is None, the returned mime bundle has
@@ -528,7 +529,6 b' class Inspector(Colorable):'
528 Formatters returning strings are supported but this behavior is deprecated.
529 Formatters returning strings are supported but this behavior is deprecated.
529
530
530 """
531 """
531 text = cast_unicode(text)
532 defaults = {
532 defaults = {
533 'text/plain': text,
533 'text/plain': text,
534 'text/html': '<pre>' + text + '</pre>'
534 'text/html': '<pre>' + text + '</pre>'
@@ -591,7 +591,7 b' class Inspector(Colorable):'
591 'text/html': '',
591 'text/html': '',
592 }
592 }
593
593
594 def append_field(bundle, title, key, formatter=None):
594 def append_field(bundle, title:str, key:str, formatter=None):
595 field = info[key]
595 field = info[key]
596 if field is not None:
596 if field is not None:
597 formatted_field = self._mime_format(field, formatter)
597 formatted_field = self._mime_format(field, formatter)
@@ -711,7 +711,8 b' class Inspector(Colorable):'
711 Returns
711 Returns
712 =======
712 =======
713
713
714 An object info dict with known fields from `info_fields`.
714 An object info dict with known fields from `info_fields`. Keys are
715 strings, values are string or None.
715 """
716 """
716
717
717 if info is None:
718 if info is None:
General Comments 0
You need to be logged in to leave comments. Login now