Check whether the source *src* contains the docstring *doc*. This is a helper function to skip displaying the docstring if the source already contains it, avoiding repetition of information.
(src, doc)
| 1091 | |
| 1092 | @staticmethod |
| 1093 | def _source_contains_docstring(src, doc): |
| 1094 | """ |
| 1095 | Check whether the source *src* contains the docstring *doc*. |
| 1096 | |
| 1097 | This is a helper function to skip displaying the docstring if the |
| 1098 | source already contains it, avoiding repetition of information. |
| 1099 | """ |
| 1100 | try: |
| 1101 | (def_node,) = ast.parse(dedent(src)).body |
| 1102 | return ast.get_docstring(def_node) == doc # type: ignore[arg-type] |
| 1103 | except Exception: |
| 1104 | # The source can become invalid or even non-existent (because it |
| 1105 | # is re-fetched from the source file) so the above code fail in |
| 1106 | # arbitrary ways. |
| 1107 | return False |
| 1108 | |
| 1109 | def psearch(self,pattern,ns_table,ns_search=[], |
| 1110 | ignore_case=False,show_all=False, *, list_types=False): |