Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
boiler struct for api ext
Signed-off-by: Dibri Nsofor <[email protected]>
  • Loading branch information
dibrinsofor committed Sep 5, 2026
commit 420aa866991fab82c1f6e71ca5806264440e4608
39 changes: 39 additions & 0 deletions mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class C: pass
MypyFile,
SymbolTableNode,
TypeInfo,
FuncDef,
ReturnStmt
)
from mypy.options import Options
from mypy.types import (
Expand Down Expand Up @@ -516,6 +518,35 @@ class DynamicClassDefContext(NamedTuple):
name: str # The name this class is being assigned to
api: SemanticAnalyzerPluginInterface

# A context for a function hook signature after available after decl.
class FunctionDefContext(NamedTuple):
definition: FuncDef
declared_signature: CallableType
api: SemanticAnalyzerPluginInterface

class ReturnSite(NamedTuple):
statement: ReturnStmt
inferred_type: Type

# A context for a function hook after the body is checked.
class FunctionBodyContext(NamedTuple):
definition: FuncDef
declared_signature: CallableType # preserves the user annotations
inferred_return_type: Type # inferred from return exprs in func, can be None
return_sites: tuple[ReturnSite, ...]
can_fall_through: bool # tracks definitions with multiple exists (e.g early returns)
api: CheckerPluginInterface

# None here means inferred function return type is not propagated
class FunctionBodyResult(NamedTuple):
refined_return: Type | None = None

# Supplying this callback tells mypy that this body's inferred information may affect the function's published signature.
class FunctionDefHookResult(NamedTuple):
after_body: FunctionBodyHook | None = None

FunctionBodyHook = Callable[[FunctionBodyContext], FunctionBodyResult]
FunctionDefHook = Callable[[FunctionDefContext], FunctionDefHookResult]

@mypyc_attr(allow_interpreted_subclasses=True)
class Plugin(CommonPluginApi):
Expand Down Expand Up @@ -819,6 +850,14 @@ def get_dynamic_class_hook(
"""
return None

def get_function_def_hook(
self, fullname: str
) -> FunctionDefHook:
"""FILL

"""
return None


T = TypeVar("T")

Expand Down