(state: State, data: ReadBuffer)
| 629 | |
| 630 | |
| 631 | def 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 | |
| 686 | def read_class_def(state: State, data: ReadBuffer) -> ClassDef: |
no test coverage detected
searching dependent graphs…