(
file: io.TextIOWrapper,
)
| 151 | |
| 152 | |
| 153 | def extract_code_blocks( |
| 154 | file: io.TextIOWrapper, |
| 155 | ) -> Iterator[CodeBlock]: |
| 156 | lines_iter = iter(enumerate(file)) |
| 157 | |
| 158 | while True: |
| 159 | next_item = next(lines_iter, None) |
| 160 | if next_item is None: |
| 161 | break |
| 162 | lineno, line = next_item |
| 163 | match = REGEX_CODE_BLOCK.match(line) |
| 164 | if match: |
| 165 | indent = match.group('indent') |
| 166 | indent_size = len(indent) |
| 167 | code_block_start_lineno = lineno + 1 |
| 168 | code_block_lines = [line] |
| 169 | indent_regex = re.compile(rf"\s{{{indent_size + 1}}}") |
| 170 | while True: |
| 171 | next_item = next(lines_iter, None) |
| 172 | if next_item is None: |
| 173 | break |
| 174 | lineno, line = next_item |
| 175 | if not indent_regex.match(line) and not is_blank_line(line): |
| 176 | break |
| 177 | code_block_lines.append(line) |
| 178 | yield CodeBlock(code_block_lines, code_block_start_lineno) |
| 179 | |
| 180 | |
| 181 | def check_code_block_indentation( |
no test coverage detected