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

Function read_class_def

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

Source from the content-addressed store, hash-verified

684
685
686def 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
727def read_type_alias_stmt(state: State, data: ReadBuffer) -> TypeAliasStmt:

Callers 1

read_statementFunction · 0.85

Calls 13

read_strFunction · 0.90
ClassDefClass · 0.90
read_blockFunction · 0.85
read_expression_listFunction · 0.85
expect_tagFunction · 0.85
read_expressionFunction · 0.85
rangeClass · 0.85
read_type_paramsFunction · 0.85
dictClass · 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…