parameters: (self)
return_statement: return None, None
docstring: Parse the function or method.
docstring_summary: Parse the function or method.
docstring_tokens: Parse the function or method .
function: def parse(self):
          """Parse the function or method."""
          logger.debug("fn: %r", self.fn)
          if isinstance(self.fn, (types.FunctionType, types.MethodType)):
              try:
                  lines, self.line_offset = inspect.getsourcelines(self.fn)
              except OSError as e:
                  if e.__str__() == "could not get source code":
                      raise OSError(f"Mindspore can not compile temporary source code in terminal. "
                                    f"Please write source code to a python file and run the file.")
                  raise e
              original_src = ''.join(lines)
              hexstr = hashlib.sha256(original_src.encode()).hexdigest()
              ast_tokens_cache = Parser.ast_cache.get(hexstr)
              if not ast_tokens_cache:
                  src = dedent(original_src)
                  self.col_offset = \
                      len(original_src.split('\n')[0]) - len(src.split('\n')[0])
                  logger.debug("Get source: %s", src)
                  try:
                      ast_tokens = asttokens.ASTTokens(src, parse=True)
                  except IndentationError as idt_err:
                      idt_err.filename = self.filename
                      idt_err.lineno = self.line_offset
                      idt_err.msg = f"There are incorrect indentations in definition or comment of function: " \
                                    f"'{self.fn.__qualname__}'."
                      raise idt_err
                  ast_tokens_cache = (ast_tokens, self.col_offset)
                  Parser.ast_cache[hexstr] = ast_tokens_cache
              else:
                  self.col_offset = ast_tokens_cache[1]
              return ast_tokens_cache[0], ast_tokens_cache[0].tree
  
          logger.error("Fn type is invalid")
          return None, None
function_tokens: def parse ( self ) : logger . debug ( "fn: %r" , self . fn ) if isinstance ( self . fn , ( types . FunctionType , types . MethodType ) ) : try : lines , self . line_offset = inspect . getsourcelines ( self . fn ) except OSError as e : if e . __str__ ( ) == "could not get source code" : raise OSError ( f"Mindspore can not compile temporary source code in terminal. " f"Please write source code to a python file and run the file." ) raise e original_src = '' . join ( lines ) hexstr = hashlib . sha256 ( original_src . encode ( ) ) . hexdigest ( ) ast_tokens_cache = Parser . ast_cache . get ( hexstr ) if not ast_tokens_cache : src = dedent ( original_src ) self . col_offset = len ( original_src . split ( '\n' ) [ 0 ] ) - len ( src . split ( '\n' ) [ 0 ] ) logger . debug ( "Get source: %s" , src ) try : ast_tokens = asttokens . ASTTokens ( src , parse = True ) except IndentationError as idt_err : idt_err . filename = self . filename idt_err . lineno = self . line_offset idt_err . msg = f"There are incorrect indentations in definition or comment of function: " f"'{self.fn.__qualname__}'." raise idt_err ast_tokens_cache = ( ast_tokens , self . col_offset ) Parser . ast_cache [ hexstr ] = ast_tokens_cache else : self . col_offset = ast_tokens_cache [ 1 ] return ast_tokens_cache [ 0 ] , ast_tokens_cache [ 0 ] . tree logger . error ( "Fn type is invalid" ) return None , None