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

Function read_func_def

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

Source from the content-addressed store, hash-verified

629
630
631def read_func_def(state: State, data: ReadBuffer) -> FuncDef:
632 state.num_funcs += 1
633
634 name = read_str(data)
635 arguments, has_ann = read_parameters(state, data)
636
637 if special_function_elide_names(name):
638 for arg in arguments:
639 arg.pos_only = True
640
641 body = read_block(state, data)
642 is_async = read_bool(data)
643
644 # Type parameters (PEP 695)
645 has_type_params = read_bool(data)
646 if has_type_params:
647 type_params = read_type_params(state, data)
648 else:
649 type_params = None
650
651 has_return_type = read_bool(data)
652 if has_return_type:
653 return_type = read_type(state, data)
654 has_ann = True
655 else:
656 return_type = None
657
658 if has_ann:
659 typ = CallableType(
660 [
661 arg.type_annotation if arg.type_annotation else AnyType(TypeOfAny.unannotated)
662 for arg in arguments
663 ],
664 [arg.kind for arg in arguments],
665 [None if arg.pos_only else arg.variable.name for arg in arguments],
666 return_type if return_type else AnyType(TypeOfAny.unannotated),
667 _dummy_fallback,
668 )
669 else:
670 typ = None
671
672 func_def = FuncDef(name, arguments, body, typ=typ, type_args=type_params)
673 if is_async:
674 func_def.is_coroutine = True
675 read_loc(data, func_def)
676 if typ:
677 typ.line = func_def.line
678 typ.column = func_def.column
679 typ.definition = func_def
680 # TODO: This seems wasteful, can we avoid it?
681 func_def.unanalyzed_type = typ.copy_modified()
682 expect_end_tag(data)
683 return func_def
684
685
686def read_class_def(state: State, data: ReadBuffer) -> ClassDef:

Callers 1

read_statementFunction · 0.85

Calls 12

copy_modifiedMethod · 0.95
read_strFunction · 0.90
CallableTypeClass · 0.90
AnyTypeClass · 0.90
FuncDefClass · 0.90
read_parametersFunction · 0.85
read_blockFunction · 0.85
read_type_paramsFunction · 0.85
read_locFunction · 0.85
expect_end_tagFunction · 0.85
read_typeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…