|
19 | 19 | from math import gcd |
20 | 20 | from typing import NamedTuple |
21 | 21 |
|
| 22 | +from .cst_kit import IdentifierFinder |
22 | 23 |
|
23 | | -def get_line_indent_count_from_lines(lines: Sequence[str], index: int) -> int: |
24 | | - return get_line_indent_count(lines[index]) |
25 | | - |
26 | | - |
27 | | -def get_line_indent_count(line: str) -> int: |
28 | | - """ |
29 | | - Count the number of leading whitespace characters in a line. |
30 | | -
|
31 | | - Args: |
32 | | - line (str): The input line to analyze. |
33 | | -
|
34 | | - Returns: |
35 | | - int: The number of leading whitespace characters. |
36 | | -
|
37 | | - Example: |
38 | | - >>> get_line_indent_count(" Hello") |
39 | | - 4 |
40 | | - >>> get_line_indent_count("\t\tWorld") |
41 | | - 2 |
42 | | - """ |
43 | | - return len(line) - len(line.lstrip()) |
44 | | - |
45 | | - |
46 | | -def extract_indentation(line: str) -> str: |
47 | | - """ |
48 | | - Extract the leading whitespace from a given line. |
49 | | -
|
50 | | - This function identifies and returns the leading whitespace characters |
51 | | - (spaces or tabs) from the beginning of the input line. |
52 | | -
|
53 | | - Args: |
54 | | - line (str): The input line to process. |
55 | | -
|
56 | | - Returns: |
57 | | - str: The leading whitespace of the line. |
58 | | -
|
59 | | - Examples: |
60 | | - >>> extract_indentation(" Hello") |
61 | | - ' ' |
62 | | - >>> extract_indentation("\t\tWorld") |
63 | | - '\t\t' |
64 | | - >>> extract_indentation("No indentation") |
65 | | - '' |
66 | | - """ |
67 | | - return line[:len(line) - len(line.lstrip())] |
68 | | - |
| 24 | +from .line_kit import get_line_indent_count, extract_indentation |
69 | 25 |
|
70 | 26 | class IndentationInfo(NamedTuple): |
71 | 27 | """ |
@@ -117,7 +73,8 @@ def default(cls) -> 'IndentationInfo': |
117 | 73 | @classmethod |
118 | 74 | def shift_indentation(cls, |
119 | 75 | content: Sequence[str], target_lines: Sequence[str], target_reference_indentation_count: int, |
120 | | - relindent_level: int | None |
| 76 | + relindent_level: int | None = None, |
| 77 | + identifier_finder: IdentifierFinder | None = None |
121 | 78 | ) -> list[str]: |
122 | 79 | """ |
123 | 80 | Returns 'content' with shifted indentation based on a relative indent level and a reference indentation count. |
@@ -165,7 +122,10 @@ def _shift_indentation( |
165 | 122 | return [raw_line_adjuster(line) for line in content] |
166 | 123 |
|
167 | 124 | @classmethod |
168 | | - def from_content(cls, content: str | Sequence[str]) -> 'IndentationInfo': |
| 125 | + def from_content( |
| 126 | + cls, content: str | Sequence[str], |
| 127 | + identifier_finder: IdentifierFinder | None = None |
| 128 | + ) -> 'IndentationInfo': |
169 | 129 | """ |
170 | 130 | Analyzes the indentation in the given content and creates an IndentationInfo instance. |
171 | 131 |
|
|
0 commit comments