Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/libcst/_tabs.py: 9%
11 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:43 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:43 +0000
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2#
3# This source code is licensed under the MIT license found in the
4# LICENSE file in the root directory of this source tree.
7def expand_tabs(line: str) -> str:
8 """
9 Tabs are treated as 1-8 spaces according to
10 https://docs.python.org/3/reference/lexical_analysis.html#indentation
12 Given a string with tabs, this removes all tab characters and replaces them with the
13 appropriate number of spaces.
14 """
15 result_list = []
16 total = 0
17 for ch in line:
18 if ch == "\t":
19 prev_total = total
20 total = ((total + 8) // 8) * 8
21 result_list.append(" " * (total - prev_total))
22 else:
23 total += 1
24 result_list.append(ch)
26 return "".join(result_list)