(stub: nodes.FuncItem)
| 958 | |
| 959 | @staticmethod |
| 960 | def from_funcitem(stub: nodes.FuncItem) -> Signature[nodes.Argument]: |
| 961 | stub_sig: Signature[nodes.Argument] = Signature() |
| 962 | stub_args = maybe_strip_cls(stub.name, stub.arguments) |
| 963 | for stub_arg in stub_args: |
| 964 | if stub_arg.kind.is_positional(): |
| 965 | stub_sig.pos.append(stub_arg) |
| 966 | elif stub_arg.kind.is_named(): |
| 967 | stub_sig.kwonly[stub_arg.variable.name] = stub_arg |
| 968 | elif stub_arg.kind == nodes.ARG_STAR: |
| 969 | stub_sig.varpos = stub_arg |
| 970 | elif stub_arg.kind == nodes.ARG_STAR2: |
| 971 | if stub_arg.variable.type is not None and isinstance( |
| 972 | (typed_dict_arg := mypy.types.get_proper_type(stub_arg.variable.type)), |
| 973 | mypy.types.TypedDictType, |
| 974 | ): |
| 975 | for key_name, key_type in typed_dict_arg.items.items(): |
| 976 | optional = key_name not in typed_dict_arg.required_keys |
| 977 | stub_sig.kwonly[key_name] = nodes.Argument( |
| 978 | nodes.Var(key_name, key_type), |
| 979 | type_annotation=key_type, |
| 980 | initializer=nodes.EllipsisExpr() if optional else None, |
| 981 | kind=nodes.ARG_NAMED_OPT if optional else nodes.ARG_NAMED, |
| 982 | pos_only=False, |
| 983 | ) |
| 984 | else: |
| 985 | stub_sig.varkw = stub_arg |
| 986 | else: |
| 987 | raise AssertionError |
| 988 | return stub_sig |
| 989 | |
| 990 | @staticmethod |
| 991 | def from_inspect_signature(signature: inspect.Signature) -> Signature[inspect.Parameter]: |
no test coverage detected