Check the two (inner) block structures of the corresponding code block given by `split_code_into_blocks` match. For the case of `class`, they must be of one of the following 3 cases: - a single block without name: class foo: a = 1 - a consecutive s
(splits_1, splits_2, is_class, filename)
| 189 | |
| 190 | |
| 191 | def _sanity_check_splits(splits_1, splits_2, is_class, filename): |
| 192 | """Check the two (inner) block structures of the corresponding code block given by `split_code_into_blocks` match. |
| 193 | |
| 194 | For the case of `class`, they must be of one of the following 3 cases: |
| 195 | |
| 196 | - a single block without name: |
| 197 | |
| 198 | class foo: |
| 199 | a = 1 |
| 200 | |
| 201 | - a consecutive sequence of (1 or more) blocks with name |
| 202 | |
| 203 | class foo: |
| 204 | |
| 205 | def f(x): |
| 206 | return x |
| 207 | |
| 208 | - a block without name, followed by a consecutive sequence of (1 or more) blocks with name |
| 209 | |
| 210 | class foo: |
| 211 | a = 1 |
| 212 | |
| 213 | def f(x): |
| 214 | return x |
| 215 | |
| 216 | def g(x): |
| 217 | return None |
| 218 | |
| 219 | The 2 code snippets that give `splits_1` and `splits_2` have to be in the same case to pass this check, but the |
| 220 | number of blocks with name in the consecutive sequence is not taken into account. |
| 221 | |
| 222 | For the case of `function or method`, we don't require it to be in one of the above 3 cases. However, the structure |
| 223 | of`splits_1` and `splits_2` have to match exactly. In particular, the number of blocks with name in a consecutive |
| 224 | sequence is taken into account. |
| 225 | """ |
| 226 | block_names_1 = [] |
| 227 | block_names_2 = [] |
| 228 | |
| 229 | for block in splits_1[1:]: |
| 230 | if block[0].startswith("_block_without_name_"): |
| 231 | block_names_1.append("block_without_name") |
| 232 | elif not block[0].startswith("_empty_block_") and ( |
| 233 | not is_class or len(block_names_1) == 0 or block_names_1[-1].startswith("block_without_name") |
| 234 | ): |
| 235 | block_names_1.append("block_with_name") |
| 236 | |
| 237 | for block in splits_2[1:]: |
| 238 | if block[0].startswith("_block_without_name_"): |
| 239 | block_names_2.append("block_without_name") |
| 240 | elif not block[0].startswith("_empty_block_") and ( |
| 241 | not is_class or len(block_names_2) == 0 or block_names_2[-1].startswith("block_without_name") |
| 242 | ): |
| 243 | block_names_2.append("block_with_name") |
| 244 | |
| 245 | if is_class: |
| 246 | if block_names_1 not in [ |
| 247 | ["block_without_name"], |
| 248 | ["block_with_name"], |
no outgoing calls
no test coverage detected