Skip to content

Elaboration - #21951

Draft
dibrinsofor wants to merge 14 commits into
python:masterfrom
dibrinsofor:elaboration
Draft

Elaboration#21951
dibrinsofor wants to merge 14 commits into
python:masterfrom
dibrinsofor:elaboration

Conversation

@dibrinsofor

Copy link
Copy Markdown

Fixes #13668, and #18166. Lays ground work for #7758

This take extends the current plugin API to support type directed refinements of function return types after mypy checks a function body, the rechecks affected call sites until a stable refined point is reached. Some messy work is done to propagate refined type information.

work could be adapted to support other annotation sites: variables, classes, parameters, etc.

  1. supported:
from typing import Any

def bad(x: int) -> Any:
    return str(x)

reveal_type(bad(1))  # N: Revealed type is "builtins.str"
value: int = bad(1)  # Error! plugin developers can surface this mismatch
  1. supported:
def some_method_with_union_return(some_input: str | int) -> str | int:
    return some_input


def some_other_method() -> None:
    some_method_with_union_return(5)


def another_method() -> None:
    some_method_with_union_return("foo")

unsupported:

from typing import Any

class Settings:
    retries: Any = "3"

reveal_type(Settings().retries)  # N: Revealed type is "Any"
retries: int = Settings().retries

No support to surface and refine the type of retries.

dibrinsofor and others added 14 commits September 3, 2026 19:08
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow custom type checking via plugin for function definitions

1 participant