@@ -32,23 +32,18 @@ def dedent(content):
32
32
unindented text on the initial line.
33
33
"""
34
34
content = force_text (content )
35
- whitespace_counts = [
36
- len (line ) - len (line .lstrip (' ' ))
37
- for line in content .splitlines ()[1 :] if line .lstrip ()
38
- ]
39
- tab_counts = [
40
- len (line ) - len (line .lstrip ('\t ' ))
41
- for line in content .splitlines ()[1 :] if line .lstrip ()
42
- ]
35
+ lines = [line for line in content .splitlines ()[1 :] if line .lstrip ()]
43
36
44
37
# unindent the content if needed
45
- if whitespace_counts :
46
- whitespace_pattern = '^' + (' ' * min (whitespace_counts ))
47
- content = re .sub (re .compile (whitespace_pattern , re .MULTILINE ), '' , content )
48
- elif tab_counts :
49
- whitespace_pattern = '^' + ('\t ' * min (whitespace_counts ))
50
- content = re .sub (re .compile (whitespace_pattern , re .MULTILINE ), '' , content )
51
-
38
+ if lines :
39
+ whitespace_counts = min ([len (line ) - len (line .lstrip (' ' )) for line in lines ])
40
+ tab_counts = min ([len (line ) - len (line .lstrip ('\t ' )) for line in lines ])
41
+ if whitespace_counts :
42
+ whitespace_pattern = '^' + (' ' * whitespace_counts )
43
+ content = re .sub (re .compile (whitespace_pattern , re .MULTILINE ), '' , content )
44
+ elif tab_counts :
45
+ whitespace_pattern = '^' + ('\t ' * tab_counts )
46
+ content = re .sub (re .compile (whitespace_pattern , re .MULTILINE ), '' , content )
52
47
return content .strip ()
53
48
54
49
0 commit comments