parameters: (func)
docstring: Attempts to retrieve a reliable function code hash.
  
          The reason we don't use inspect.getsource is that it caches the
          source, whereas we want this to be modified on the fly when the
          function is modified.
  
          Returns
          -------
          func_code: string
              The function code
          source_file: string
              The path to the file in which the function is defined.
          first_line: int
              The first line of the code in the source file.
  
          Notes
          ------
          This function does a bit more magic than inspect, and is thus
          more robust.
docstring_summary: Attempts to retrieve a reliable function code hash.
docstring_tokens: Attempts to retrieve a reliable function code hash .
function: def get_func_code(func):
      """ Attempts to retrieve a reliable function code hash.
  
          The reason we don't use inspect.getsource is that it caches the
          source, whereas we want this to be modified on the fly when the
          function is modified.
  
          Returns
          -------
          func_code: string
              The function code
          source_file: string
              The path to the file in which the function is defined.
          first_line: int
              The first line of the code in the source file.
  
          Notes
          ------
          This function does a bit more magic than inspect, and is thus
          more robust.
      """
      source_file = None
      try:
          code = func.__code__
          source_file = code.co_filename
          if not os.path.exists(source_file):
              # Use inspect for lambda functions and functions defined in an
              # interactive shell, or in doctests
              source_code = ''.join(inspect.getsourcelines(func)[0])
              line_no = 1
              if source_file.startswith('<doctest '):
                  source_file, line_no = re.match(
                              '\<doctest (.*\.rst)\[(.*)\]\>',
                              source_file).groups()
                  line_no = int(line_no)
                  source_file = '<doctest %s>' % source_file
              return source_code, source_file, line_no
          # Try to retrieve the source code.
          with open_py_source(source_file) as source_file_obj:
              first_line = code.co_firstlineno
              # All the lines after the function definition:
              source_lines = list(islice(source_file_obj, first_line - 1, None))
          return ''.join(inspect.getblock(source_lines)), source_file, first_line
      except:
          # If the source code fails, we use the hash. This is fragile and
          # might change from one session to another.
          if hasattr(func, '__code__'):
              # Python 3.X
              return str(func.__code__.__hash__()), source_file, -1
          else:
              # Weird objects like numpy ufunc don't have __code__
              # This is fragile, as quite often the id of the object is
              # in the repr, so it might not persist across sessions,
              # however it will work for ufuncs.
              return repr(func), source_file, -1
function_tokens: def get_func_code ( func ) : source_file = None try : code = func . __code__ source_file = code . co_filename if not os . path . exists ( source_file ) : # Use inspect for lambda functions and functions defined in an # interactive shell, or in doctests source_code = '' . join ( inspect . getsourcelines ( func ) [ 0 ] ) line_no = 1 if source_file . startswith ( '<doctest ' ) : source_file , line_no = re . match ( '\<doctest (.*\.rst)\[(.*)\]\>' , source_file ) . groups ( ) line_no = int ( line_no ) source_file = '<doctest %s>' % source_file return source_code , source_file , line_no # Try to retrieve the source code. with open_py_source ( source_file ) as source_file_obj : first_line = code . co_firstlineno # All the lines after the function definition: source_lines = list ( islice ( source_file_obj , first_line - 1 , None ) ) return '' . join ( inspect . getblock ( source_lines ) ) , source_file , first_line except : # If the source code fails, we use the hash. This is fragile and # might change from one session to another. if hasattr ( func , '__code__' ) : # Python 3.X return str ( func . __code__ . __hash__ ( ) ) , source_file , - 1 else : # Weird objects like numpy ufunc don't have __code__ # This is fragile, as quite often the id of the object is # in the repr, so it might not persist across sessions, # however it will work for ufuncs. return repr ( func ) , source_file , - 1