(state: State, data: ReadBuffer)
| 684 | |
| 685 | |
| 686 | def read_class_def(state: State, data: ReadBuffer) -> ClassDef: |
| 687 | name = read_str(data) |
| 688 | body = read_block(state, data) |
| 689 | base_type_exprs = read_expression_list(state, data) |
| 690 | |
| 691 | expect_tag(data, LIST_GEN) |
| 692 | n_decorators = read_int_bare(data) |
| 693 | decorators = [read_expression(state, data) for _ in range(n_decorators)] |
| 694 | |
| 695 | # Type parameters (PEP 695) |
| 696 | has_type_params = read_bool(data) |
| 697 | if has_type_params: |
| 698 | type_params = read_type_params(state, data) |
| 699 | else: |
| 700 | type_params = None |
| 701 | |
| 702 | expect_tag(data, DICT_STR_GEN) |
| 703 | n_keywords = read_int_bare(data) |
| 704 | keywords = [] |
| 705 | for _ in range(n_keywords): |
| 706 | key = read_str(data) |
| 707 | value = read_expression(state, data) |
| 708 | keywords.append((key, value)) |
| 709 | |
| 710 | metaclass = dict(keywords).get("metaclass") if keywords else None |
| 711 | |
| 712 | class_def = ClassDef( |
| 713 | name, |
| 714 | body, |
| 715 | base_type_exprs=base_type_exprs if base_type_exprs else None, |
| 716 | metaclass=metaclass, |
| 717 | # Note we keep metaclass in keywords as well, to match the old parser. |
| 718 | keywords=keywords if keywords else None, |
| 719 | type_args=type_params, |
| 720 | ) |
| 721 | class_def.decorators = decorators |
| 722 | read_loc(data, class_def) |
| 723 | expect_end_tag(data) |
| 724 | return class_def |
| 725 | |
| 726 | |
| 727 | def read_type_alias_stmt(state: State, data: ReadBuffer) -> TypeAliasStmt: |
no test coverage detected
searching dependent graphs…