Skip to content

Commit 8a24452

Browse files
committed
Copy whitespace from original file to preserve spaces vs tabs
1 parent 2df3570 commit 8a24452

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/unasync/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _tokenize(f):
149149
space = ""
150150
if tok.start > last_end:
151151
assert tok.start[0] == last_end[0]
152-
space = " " * (tok.start[1] - last_end[1])
152+
space = tok.line[last_end[1] : tok.start[1]]
153153
yield (space, tok.type, tok.string)
154154

155155
last_end = tok.end

tests/data/async/tabs.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# fmt: off
2+
async def dummy():
3+
await dummy2() # This line is indented with a tab that should be preserved
4+
# fmt: on
5+
6+
7+
async def dummy2():
8+
await dummy() # This one uses 4 spaces and these should also be preserved

tests/data/sync/tabs.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# fmt: off
2+
def dummy():
3+
dummy2() # This line is indented with a tab that should be preserved
4+
# fmt: on
5+
6+
7+
def dummy2():
8+
dummy() # This one uses 4 spaces and these should also be preserved

0 commit comments

Comments
 (0)