def get_indentation ( func ) : src_lines = getsourcelines ( func ) [ 0 ] for line in src_lines : if not ( line . startswith ( '@' ) or line . startswith ( 'def' ) or line . lstrip ( ) . startswith ( '#' ) ) : return line [ : len ( line ) - len ( line . lstrip ( ) ) ] return pytypes . default_indent
python comments function indented
Extracts a function s indentation as a string In contrast to an inspect . indentsize based implementation this function preserves tabs if present .
def get_indentation(func):
    """Extracts a function's indentation as a string,
    In contrast to an inspect.indentsize based implementation,
    this function preserves tabs if present.
    """
    src_lines = getsourcelines(func)[0]
    for line in src_lines:
        if not (line.startswith('@') or line.startswith('def') or line.lstrip().startswith('#')):
            return line[:len(line) - len(line.lstrip())]
    return pytypes.default_indent