##// END OF EJS Templates
In obj??, display the docstring if it is not in the source....
Antony Lee -
Show More
@@ -13,6 +13,7 b' reference the name under which an object is being read.'
13 13 __all__ = ['Inspector','InspectColors']
14 14
15 15 # stdlib modules
16 import ast
16 17 import inspect
17 18 from inspect import signature
18 19 import linecache
@@ -630,10 +631,10 b' class Inspector(Colorable):'
630 631 # Functions, methods, classes
631 632 append_field(_mime, 'Signature', 'definition', code_formatter)
632 633 append_field(_mime, 'Init signature', 'init_definition', code_formatter)
634 append_field(_mime, 'Docstring', 'docstring', formatter)
633 635 if detail_level > 0 and info['source']:
634 636 append_field(_mime, 'Source', 'source', code_formatter)
635 637 else:
636 append_field(_mime, 'Docstring', 'docstring', formatter)
637 638 append_field(_mime, 'Init docstring', 'init_docstring', formatter)
638 639
639 640 append_field(_mime, 'File', 'file')
@@ -821,7 +822,7 b' class Inspector(Colorable):'
821 822 pass
822 823
823 824 # Add docstring only if no source is to be shown (avoid repetitions).
824 if ds and out.get('source', None) is None:
825 if ds and not self._source_contains_docstring(out.get('source'), ds):
825 826 out['docstring'] = ds
826 827
827 828 # Constructor docstring for classes
@@ -936,6 +937,23 b' class Inspector(Colorable):'
936 937
937 938 return object_info(**out)
938 939
940 @staticmethod
941 def _source_contains_docstring(src, doc):
942 """
943 Check whether the source *src* contains the docstring *doc*.
944
945 This is is helper function to skip displaying the docstring if the
946 source already contains it, avoiding repetition of information.
947 """
948 try:
949 def_node, = ast.parse(dedent(src)).body
950 return ast.get_docstring(def_node) == doc
951 except Exception:
952 # The source can become invalid or even non-existent (because it
953 # is re-fetched from the source file) so the above code fail in
954 # arbitrary ways.
955 return False
956
939 957 def psearch(self,pattern,ns_table,ns_search=[],
940 958 ignore_case=False,show_all=False):
941 959 """Search namespaces with wildcards for objects.
General Comments 0
You need to be logged in to leave comments. Login now