MCPcopy Index your code
hub / github.com/python/mypy / read_try_stmt

Function read_try_stmt

mypy/nativeparse.py:781–829  ·  view source on GitHub ↗
(state: State, data: ReadBuffer)

Source from the content-addressed store, hash-verified

779
780
781def read_try_stmt(state: State, data: ReadBuffer) -> TryStmt:
782 body = read_block(state, data)
783 num_handlers = read_int(data)
784
785 types_list: list[Expression | None] = []
786 for _ in range(num_handlers):
787 has_type = read_bool(data)
788 if has_type:
789 exc_type = read_expression(state, data)
790 types_list.append(exc_type)
791 else:
792 types_list.append(None)
793
794 vars_list: list[NameExpr | None] = []
795 for _ in range(num_handlers):
796 has_name = read_bool(data)
797 if has_name:
798 var_name = read_str(data)
799 var_expr = NameExpr(var_name)
800 read_loc(data, var_expr)
801 vars_list.append(var_expr)
802 else:
803 vars_list.append(None)
804
805 handlers = []
806 for _ in range(num_handlers):
807 handler_body = read_block(state, data)
808 handlers.append(handler_body)
809
810 has_else = read_bool(data)
811 if has_else:
812 else_body = read_block(state, data)
813 else:
814 else_body = None
815
816 has_finally = read_bool(data)
817 if has_finally:
818 finally_body = read_block(state, data)
819 else:
820 finally_body = None
821
822 # except* (Python 3.11+)
823 is_star = read_bool(data)
824
825 stmt = TryStmt(body, vars_list, types_list, handlers, else_body, finally_body)
826 stmt.is_star = is_star
827 read_loc(data, stmt)
828 expect_end_tag(data)
829 return stmt
830
831
832def read_type(state: State, data: ReadBuffer) -> Type:

Callers 1

read_statementFunction · 0.85

Calls 10

read_intFunction · 0.90
read_strFunction · 0.90
NameExprClass · 0.90
TryStmtClass · 0.90
read_blockFunction · 0.85
rangeClass · 0.85
read_expressionFunction · 0.85
read_locFunction · 0.85
expect_end_tagFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…