(state: State, data: ReadBuffer)
| 279 | |
| 280 | |
| 281 | def read_statement(state: State, data: ReadBuffer) -> Statement: |
| 282 | # Branches ordered by frequency (based on mypy self-check) |
| 283 | tag = read_tag(data) |
| 284 | stmt: Statement |
| 285 | if tag == nodes.ASSIGNMENT_STMT: |
| 286 | lvalues = read_expression_list(state, data) |
| 287 | rvalue = read_expression(state, data) |
| 288 | has_type = read_bool(data) |
| 289 | if has_type: |
| 290 | type_annotation = read_type(state, data) |
| 291 | else: |
| 292 | type_annotation = None |
| 293 | new_syntax = read_bool(data) |
| 294 | a = AssignmentStmt(lvalues, rvalue, type=type_annotation, new_syntax=new_syntax) |
| 295 | read_loc(data, a) |
| 296 | # If rvalue is TempNode, copy location from AssignmentStmt |
| 297 | if isinstance(rvalue, TempNode): |
| 298 | set_line_column_range(rvalue, a) |
| 299 | expect_end_tag(data) |
| 300 | return a |
| 301 | elif tag == nodes.EXPR_STMT: |
| 302 | es = ExpressionStmt(read_expression(state, data)) |
| 303 | set_line_column_range(es, es.expr) |
| 304 | expect_end_tag(data) |
| 305 | return es |
| 306 | elif tag == nodes.IF_STMT: |
| 307 | expr = read_expression(state, data) |
| 308 | body = read_block(state, data) |
| 309 | |
| 310 | num_elif = read_int(data) |
| 311 | elif_exprs = [] |
| 312 | elif_bodies = [] |
| 313 | for i in range(num_elif): |
| 314 | elif_exprs.append(read_expression(state, data)) |
| 315 | elif_bodies.append(read_block(state, data)) |
| 316 | |
| 317 | has_else = read_bool(data) |
| 318 | if has_else: |
| 319 | else_body = read_block(state, data) |
| 320 | else: |
| 321 | else_body = None |
| 322 | |
| 323 | # Normalize elif into nested if/else statements |
| 324 | # Build from the bottom up, starting with the final else body |
| 325 | current_else = else_body |
| 326 | |
| 327 | for elif_expr, elif_body in reversed(list(zip(elif_exprs, elif_bodies))): |
| 328 | elif_stmt = IfStmt([elif_expr], [elif_body], current_else) |
| 329 | elif_stmt.line = elif_expr.line |
| 330 | elif_stmt.column = elif_expr.column |
| 331 | if current_else is not None: |
| 332 | elif_stmt.end_line = current_else.end_line |
| 333 | elif_stmt.end_column = current_else.end_column |
| 334 | else: |
| 335 | elif_stmt.end_line = elif_body.end_line |
| 336 | elif_stmt.end_column = elif_body.end_column |
| 337 | |
| 338 | current_else = Block([elif_stmt]) |
no test coverage detected
searching dependent graphs…