generate_overload_group_stub¶
- generate_overload_group_stub(group: OverloadGroup, ctx: StubContext) str[source]¶
Emit one
@overload-decorated stub per variant in group.PEP 484 mandates that stub files contain one decorated stub per overload variant and that the concrete implementation (the non-
@overloaddef) is absent from the stub. This function produces the former; suppression of the latter is handled by the caller (generate_stub()).Each variant in
variantsmaps to aFunctionSymbolwhoseast_infoholds the raw parameter annotations from the AST pre-pass.- Parameters:
group (OverloadGroup) – The overload group from the
SymbolTable.ctx (StubContext) – The current
StubContext.
- Returns:
str – All overload stubs joined by
"\n\n", or""if the group has no variants.
Examples
>>> from stubpy.context import StubContext >>> from stubpy.symbols import OverloadGroup, FunctionSymbol >>> from stubpy.ast_pass import FunctionInfo >>> fi1 = FunctionInfo("parse", 1, raw_return_annotation="int", ... raw_arg_annotations={"x": "int"}) >>> fi2 = FunctionInfo("parse", 3, raw_return_annotation="str", ... raw_arg_annotations={"x": "str"}) >>> sym1 = FunctionSymbol("parse", 1, ast_info=fi1) >>> sym2 = FunctionSymbol("parse", 3, ast_info=fi2) >>> g = OverloadGroup("parse", 1, variants=[sym1, sym2]) >>> stub = generate_overload_group_stub(g, StubContext()) >>> stub.count("@overload") 2 >>> "@overload" in stub True
See also
Public API reference — overview of all public names.