| 9 | |
| 10 | |
| 11 | class PythonParser(LanguageParser): |
| 12 | |
| 13 | BLACKLISTED_FUNCTION_NAMES = ['__init__', '__name__', '__main__'] |
| 14 | |
| 15 | @staticmethod |
| 16 | def get_docstring(node, blob:str=None): |
| 17 | if blob: |
| 18 | logger.info('From version `0.0.6` this function will update argument in the API') |
| 19 | docstring_node = PythonParser.get_docstring_node(node) |
| 20 | |
| 21 | docstring = '' |
| 22 | if docstring_node is not None: |
| 23 | docstring = get_node_text(docstring_node[0]) |
| 24 | docstring = docstring.strip('"').strip("'").strip("#") |
| 25 | return docstring |
| 26 | |
| 27 | @staticmethod |
| 28 | def get_function_list(node): |
| 29 | res = get_node_by_kind(node, ['function_definition']) |
| 30 | return res |
| 31 | |
| 32 | @staticmethod |
| 33 | def get_class_list(node): |
| 34 | res = get_node_by_kind(node, ['class_definition']) |
| 35 | return res |
| 36 | |
| 37 | @staticmethod |
| 38 | def get_docstring_node(node): |
| 39 | docstring_node = [] |
| 40 | # traverse_type(node, docstring_node, kind=['expression_statement']) #, 'comment']) |
| 41 | for child in node.children: |
| 42 | if child.type == 'block': |
| 43 | for sub_child in child.children: |
| 44 | if sub_child.type == 'expression_statement': |
| 45 | docstring_node.append(sub_child) |
| 46 | |
| 47 | docstring_node = [node for node in docstring_node if |
| 48 | node.type == 'expression_statement' and node.children[0].type == 'string'] |
| 49 | |
| 50 | if len(docstring_node) > 0: |
| 51 | return [docstring_node[0].children[0]] # only take the first block |
| 52 | |
| 53 | return None |
| 54 | |
| 55 | @staticmethod |
| 56 | def get_comment_node(node): |
| 57 | comment_node = get_node_by_kind(node, kind=['comment', 'expression_statement']) |
| 58 | for node in comment_node[:]: |
| 59 | if node.type == 'expression_statement' and node.children[0].type != 'string': |
| 60 | comment_node.remove(node) |
| 61 | return comment_node |
| 62 | |
| 63 | @staticmethod |
| 64 | def get_function_metadata(function_node, blob: str=None) -> Dict[str, str]: |
| 65 | if blob: |
| 66 | logger.info('From version `0.0.6` this function will update argument in the API') |
| 67 | metadata = { |
| 68 | 'identifier': '', |
nothing calls this directly
no outgoing calls
no test coverage detected