Skip to content

Fix binding for callable protocol method decorators - #11875

Open
Jacky Hsu (JackyHsu-X) wants to merge 6 commits into
microsoft:mainfrom
JackyHsu-X:fix/classmethod-callable-protocol
Open

Jacky Hsu (JackyHsu-X) wants to merge 6 commits into
microsoft:mainfrom
JackyHsu-X:fix/classmethod-callable-protocol

Conversation

@JackyHsu-X

@JackyHsu-X Jacky Hsu (JackyHsu-X) commented Oct 14, 2026 •

Copy link
Copy Markdown

@classmethod currently leaves a callable object returned by an inner decorator unchanged. A normal call such as Example.method(1) then retains the cls parameter and reports a missing argument. @staticmethod similarly leaves a callable descriptor free to bind when accessed through an instance.

Use the evaluated built-in method descriptor for class instances and retain the wrapped callable type. Specialize it in its declaring class context so attributes such as Tenacity's retry, statistics, and retry_with keep their types. Staticmethods return the original wrapper and its overloads. Classmethods delegate to a wrapped descriptor's __get__ for Python 3.9 through 3.12; otherwise, bind the owner to the original call signatures, retaining overloads and method-scoped generic parameters.

When a built-in classmethod wraps another built-in classmethod on Python 3.9 through 3.12, preserve the inner descriptor before callable validation. The outer layer delegates to it with the same owner, so another layer does not need to be represented. This avoids treating the inner classmethod object as a callable or losing the wrapper type. The version boundary follows the Python documentation.

Regression samples cover sync/async methods, callable protocols with and without descriptors, overloaded signatures, method-scoped ParamSpec, wrapper attributes, generic and inherited owners, descriptor return objects, nested classmethods, and rejection of invalid calls. Related: jd/tenacity#756; the original issue reproduces without importing Tenacity.

Validation:

  • The latest nested-classmethod CLI QA reports three errors on b73c29e; the revision reports zero and preserves the original wrapper type for class and instance access.
  • The new versioned regression fails on b73c29e for targets 3.9, 3.11 and 3.12: 28 errors instead of four deliberately invalid calls. The 3.8 and 3.13 boundary controls pass. With the revision, all five pass; diagnostic locations are checked independently through the CLI.
  • All fourteen built CLI probes pass, including the latest QA, preceding QA cases, Tenacity, metadata, generic identity, and descriptor overloads/ParamSpec. Decorator8/9/10 focused tests: 11 passed.
  • Actual CPython 3.11.16 and 3.12.8 probes pass one/two/three nested layers, inheritance and custom descriptor delegation. CPython 3.14.3 confirms the nondelegating boundary. Targets 3.8/3.9/3.13 were checked statically, not run as interpreters.
  • Complete current Jest suite: 3,526 passed, 12 skipped (97 suites passed, 1 skipped), exit code 0. Used the repository-supported PYLANCE_JEST_TRANSPILE_ONLY=1 mode with separate TypeScript checking.
  • pnpm run typecheck passes for all three checked workspace packages. pnpm run check passes syncpack, ESLint and Prettier; git diff --check passes.

AI assistance was used to investigate the issue, implement the patch, and run validation.

@heejaechang

Heejae Chang (heejaechang) commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

🔴 Pyright CLI QA — e6adb496 — verdict: red

Automated CLI checks compared this change with its base revision.
94 focused check(s) completed.

Needs review: reportArgumentType no longer reported

The base reports reportArgumentType for this example; the PR does not. Is this change intended?

Reproduction and observed results

Create these files in an empty directory:

main.py

from typing import Generic, TypeVar
from support import decorate
reveal_type(0)
T = TypeVar('T')
class A(Generic[T]):
    @classmethod
    @decorate
    def cm(cls, x: T) -> T:
        return x
class Mid(A[T], Generic[T]): pass
class B(Mid[int]):
    @classmethod
    def mutate(cls) -> None:
        super().cm.items.append('bad')

pyrightconfig.json

{"include":["main.py"],"pythonVersion":"3.13","typeCheckingMode":"basic"}

support.pyi

from typing import Callable, ParamSpec, Protocol, TypeVar
P = ParamSpec('P')
R = TypeVar('R')
class Wrapper(Protocol[P, R]):
    items: list[R]
    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
def decorate(f: Callable[P, R]) -> Wrapper[P, R]: ...

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "main.py",
      "severity": "error",
      "rule": "reportArgumentType",
      "message": "Argument of type \"Literal['bad']\" cannot be assigned to parameter \"object\" of type \"int\" in function \"append\"\n  \"Literal['bad']\" is not assignable to \"int\"",
      "range": {
        "start": [
          13,
          32
        ],
        "end": [
          13,
          37
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 0,
  "diagnostics": [
    {
      "file": "main.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

Additional reproduction: Diagnostics changed for this example

The base and PR report different diagnostics for the same example. Is this change intended?

Create these files in an empty directory:

control.py

from support import decorate
from typing_extensions import assert_type, assert_never, Never
reveal_type(0)
class Base:
    @classmethod
    @decorate
    def factory(cls) -> object:
        return cls()
class Child(Base):
    def foo(self) -> str:
        return 's'
assert_type(Child.factory().foo(), str)
def bottom(x: Never) -> None:
    assert_never(x)

main.py

from support import decorate
from typing_extensions import assert_type, assert_never, Never
reveal_type(0)
class Base:
    @classmethod
    @decorate
    def factory(cls) -> object:
        return cls()
class Child(Base):
    def foo(self) -> str:
        return 's'
    @classmethod
    def consume(cls) -> str:
        return super().factory().foo()
assert_type(Child.consume(), str)
def bottom(x: Never) -> None:
    assert_never(x)

pyrightconfig.json

{"include":["main.py","control.py"],"pythonVersion":"3.13","typeCheckingMode":"basic"}

support.pyi

from typing import Callable, Protocol, TypeVar
class HasFoo(Protocol):
    def foo(self) -> str: ...
T = TypeVar('T', bound=HasFoo)
class Wrapper:
    def __call__(self, owner: type[T] = ...) -> T: ...
def decorate(f: Callable[..., object]) -> Wrapper: ...

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "control.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "error",
      "rule": "reportAssertTypeFailure",
      "message": "\"assert_type\" mismatch: expected \"str\" but received \"Unknown\"",
      "range": {
        "start": [
          11,
          12
        ],
        "end": [
          11,
          33
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "control.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"foo\" for class \"Base\"\n  Attribute \"foo\" is unknown",
      "range": {
        "start": [
          13,
          33
        ],
        "end": [
          13,
          36
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

Additional reproduction: reportAssertTypeFailure newly reported

The PR reports reportAssertTypeFailure for this example; the base does not. Is this change intended?

Create these files in an empty directory:

alias.py

from typing import Generic, TypeVar
from support import decorate
reveal_type(0)
T = TypeVar('T')
class A(Generic[T]):
    @classmethod
    @decorate
    def cm(cls, x: T) -> T:
        return x
class B(A[int]):
    @classmethod
    def mutate(cls) -> None:
        items = super().cm.items
        items.append('bad')

control.py

from typing import Generic, TypeVar
from support import decorate
reveal_type(0)
T = TypeVar('T')
class A(Generic[T]):
    @classmethod
    @decorate
    def cm(cls, x: T) -> T:
        return x
class B(A[int]):
    pass
B.cm.items.append('bad')

instance.py

from typing import Generic, TypeVar
from support import decorate
reveal_type(0)
T = TypeVar('T')
class A(Generic[T]):
    @classmethod
    @decorate
    def cm(cls, x: T) -> T:
        return x
class B(A[int]):
    def mutate(self) -> None:
        super().cm.items.append('bad')

precision.py

from typing import Generic, TypeVar
from support import decorate
reveal_type(0)
T = TypeVar('T')
class A(Generic[T]):
    @classmethod
    @decorate
    def cm(cls, x: T) -> T:
        return x
class B(A[int]):
    @classmethod
    def observe(cls) -> None:
        from typing_extensions import assert_type
        assert_type(super().cm.items, list[int])
        assert_type(super().cm.items[0].bit_length(), int)

pyrightconfig.json

{"include":["simple.py","instance.py","alias.py","precision.py","control.py"],"pythonVersion":"3.13","typeCheckingMode":"basic"}

simple.py

from typing import Generic, TypeVar
from support import decorate
reveal_type(0)
T = TypeVar('T')
class A(Generic[T]):
    @classmethod
    @decorate
    def cm(cls, x: T) -> T:
        return x
class B(A[int]):
    @classmethod
    def mutate(cls) -> None:
        super().cm.items.append('bad')

support.pyi

from typing import Callable, ParamSpec, Protocol, TypeVar
P = ParamSpec('P')
R = TypeVar('R')
class Wrapper(Protocol[P, R]):
    items: list[R]
    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
def decorate(f: Callable[P, R]) -> Wrapper[P, R]: ...

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "alias.py",
      "severity": "error",
      "rule": "reportArgumentType",
      "message": "Argument of type \"Literal['bad']\" cannot be assigned to parameter \"object\" of type \"int\" in function \"append\"\n  \"Literal['bad']\" is not assignable to \"int\"",
      "range": {
        "start": [
          13,
          21
        ],
        "end": [
          13,
          26
        ]
      }
    },
    {
      "file": "alias.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "alias.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "error",
      "rule": "reportArgumentType",
      "message": "Argument of type \"Literal['bad']\" cannot be assigned to parameter \"object\" of type \"int\" in function \"append\"\n  \"Literal['bad']\" is not assignable to \"int\"",
      "range": {
        "start": [
          11,
          18
        ],
        "end": [
          11,
          23
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "error",
      "rule": "reportArgumentType",
      "message": "Argument of type \"Literal['bad']\" cannot be assigned to parameter \"object\" of type \"int\" in function \"append\"\n  \"Literal['bad']\" is not assignable to \"int\"",
      "range": {
        "start": [
          11,
          32
        ],
        "end": [
          11,
          37
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "precision.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "precision.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "simple.py",
      "severity": "error",
      "rule": "reportArgumentType",
      "message": "Argument of type \"Literal['bad']\" cannot be assigned to parameter \"object\" of type \"int\" in function \"append\"\n  \"Literal['bad']\" is not assignable to \"int\"",
      "range": {
        "start": [
          12,
          32
        ],
        "end": [
          12,
          37
        ]
      }
    },
    {
      "file": "simple.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "simple.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "alias.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "alias.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "error",
      "rule": "reportArgumentType",
      "message": "Argument of type \"Literal['bad']\" cannot be assigned to parameter \"object\" of type \"int\" in function \"append\"\n  \"Literal['bad']\" is not assignable to \"int\"",
      "range": {
        "start": [
          11,
          18
        ],
        "end": [
          11,
          23
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "precision.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "precision.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "precision.py",
      "severity": "error",
      "rule": "reportAssertTypeFailure",
      "message": "\"assert_type\" mismatch: expected \"int\" but received \"Any\"",
      "range": {
        "start": [
          14,
          20
        ],
        "end": [
          14,
          52
        ]
      }
    },
    {
      "file": "precision.py",
      "severity": "error",
      "rule": "reportAssertTypeFailure",
      "message": "\"assert_type\" mismatch: expected \"list[int]\" but received \"Any\"",
      "range": {
        "start": [
          13,
          20
        ],
        "end": [
          13,
          36
        ]
      }
    },
    {
      "file": "simple.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          1,
          5
        ],
        "end": [
          1,
          12
        ]
      }
    },
    {
      "file": "simple.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

Needs review: reportIncompatibleVariableOverride no longer reported

The base reports reportIncompatibleVariableOverride for this example; the PR does not. Is this change intended?

Reproduction and observed results

Create these files in an empty directory:

main.py

from typing import Callable
reveal_type(0)
class IntWrapper:
    value: int = 1
    def __call__(self, owner: type[object], x: int) -> int:
        return x
class StrWrapper:
    value: str = 'bad'
    def __call__(self, owner: type[object], x: int) -> int:
        return x
def ints(f: Callable[..., int]) -> IntWrapper:
    return IntWrapper()
def strings(f: Callable[..., int]) -> StrWrapper:
    return StrWrapper()
class A:
    @classmethod
    @ints
    def method(cls, x: int) -> int:
        return x
class B(A):
    @classmethod
    @strings
    def method(cls, x: int) -> int:
        return x
def consume(obj: A) -> int:
    return obj.method.value.bit_length()

pyrightconfig.json

{"include":["main.py"],"pythonVersion":"3.13","typeCheckingMode":"basic","reportIncompatibleVariableOverride":"error","reportIncompatibleMethodOverride":"error"}

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "error",
      "rule": "reportIncompatibleVariableOverride",
      "message": "\"method\" overrides symbol of same name in class \"A\"\n  \"StrWrapper\" is not assignable to \"IntWrapper\"",
      "range": {
        "start": [
          22,
          8
        ],
        "end": [
          22,
          14
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 0,
  "diagnostics": [
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

Additional reproduction: Diagnostics changed for this example

The base and PR report different diagnostics for the same example. Is this change intended?

Create these files in an empty directory:

class_bad.py

from support import ints, strings, same, bad_return
from typing_extensions import assert_type, assert_never, Never
reveal_type(0)
class A:
    @classmethod
    @ints
    def method(cls, x: int) -> int:
        return x
class B(A):
    @classmethod
    @strings
    def method(cls, x: int) -> int:
        return x
def consume(obj: A) -> int:
    return obj.method.value.bit_length()
assert_type(consume(A()), int)
def bottom(x: Never) -> None:
    assert_never(x)

control.py

from support import ints, strings, same, bad_return
from typing_extensions import assert_type, assert_never, Never
reveal_type(0)
class A:
    @classmethod
    @ints
    def method(cls, x: int) -> int:
        return x
class B(A):
    @classmethod
    @same
    def method(cls, x: int) -> int:
        return x
def consume(obj: A) -> int:
    return obj.method.value.bit_length()
assert_type(consume(A()), int)
def bottom(x: Never) -> None:
    assert_never(x)

pyrightconfig.json

{"include":["class_bad.py","static_bad.py","control.py","return_bad.py"],"pythonVersion":"3.13","typeCheckingMode":"basic","reportIncompatibleVariableOverride":"error","reportIncompatibleMethodOverride":"error"}

return_bad.py

from support import ints, strings, same, bad_return
from typing_extensions import assert_type, assert_never, Never
reveal_type(0)
class A:
    @classmethod
    @ints
    def method(cls, x: int) -> int:
        return x
class B(A):
    @classmethod
    @bad_return
    def method(cls, x: int) -> str:
        return str(x)
def consume(obj: A) -> int:
    return obj.method.value.bit_length()
assert_type(consume(A()), int)
def bottom(x: Never) -> None:
    assert_never(x)

static_bad.py

from support import ints, strings, same, bad_return
from typing_extensions import assert_type, assert_never, Never
reveal_type(0)
class A:
    @staticmethod
    @ints
    def method(owner: type[object], x: int) -> int:
        return x
class B(A):
    @staticmethod
    @strings
    def method(owner: type[object], x: int) -> int:
        return x
def consume(obj: A) -> int:
    return obj.method.value.bit_length()
assert_type(consume(A()), int)
def bottom(x: Never) -> None:
    assert_never(x)

support.pyi

from typing import Callable, Protocol
class IntWrapper(Protocol):
    value: int
    def __call__(self, owner: type[object], x: int) -> int: ...
class StrWrapper(Protocol):
    value: str
    def __call__(self, owner: type[object], x: int) -> int: ...
class Equivalent(Protocol):
    value: int
    def __call__(self, owner: type[object], x: int) -> int: ...
class BadReturn(Protocol):
    value: int
    def __call__(self, owner: type[object], x: int) -> str: ...
def ints(f: Callable[..., int]) -> IntWrapper: ...
def strings(f: Callable[..., int]) -> StrWrapper: ...
def same(f: Callable[..., int]) -> Equivalent: ...
def bad_return(f: Callable[..., str]) -> BadReturn: ...

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "class_bad.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "class_bad.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "class_bad.py",
      "severity": "error",
      "rule": "reportIncompatibleVariableOverride",
      "message": "\"method\" overrides symbol of same name in class \"A\"\n  \"StrWrapper\" is incompatible with protocol \"IntWrapper\"\n    \"value\" is invariant because it is mutable\n    \"value\" is an incompatible type\n      \"str\" is not assignable to \"int\"",
      "range": {
        "start": [
          11,
          8
        ],
        "end": [
          11,
          14
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "return_bad.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "return_bad.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "return_bad.py",
      "severity": "error",
      "rule": "reportIncompatibleVariableOverride",
      "message": "\"method\" overrides symbol of same name in class \"A\"\n  \"BadReturn\" is incompatible with protocol \"IntWrapper\"\n    \"__call__\" is an incompatible type\n      Type \"(owner: type[object], x: int) -> str\" is not assignable to type \"(owner: type[object], x: int) -> int\"\n        Function return type \"str\" is incompatible with type \"int\"\n          \"str\" is not assignable to \"int\"",
      "range": {
        "start": [
          11,
          8
        ],
        "end": [
          11,
          14
        ]
      }
    },
    {
      "file": "static_bad.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "static_bad.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "static_bad.py",
      "severity": "error",
      "rule": "reportIncompatibleVariableOverride",
      "message": "\"method\" overrides symbol of same name in class \"A\"\n  \"StrWrapper\" is incompatible with protocol \"IntWrapper\"\n    \"value\" is invariant because it is mutable\n    \"value\" is an incompatible type\n      \"str\" is not assignable to \"int\"",
      "range": {
        "start": [
          11,
          8
        ],
        "end": [
          11,
          14
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "class_bad.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "class_bad.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "return_bad.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "return_bad.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "return_bad.py",
      "severity": "error",
      "rule": "reportIncompatibleVariableOverride",
      "message": "\"method\" overrides symbol of same name in class \"A\"\n  \"classmethod[object, (x: int), str]\" is not assignable to \"classmethod[object, (x: int), int]\"\n    Type parameter \"_R_co@classmethod\" is covariant, but \"str\" is not a subtype of \"int\"\n      \"str\" is not assignable to \"int\"",
      "range": {
        "start": [
          11,
          8
        ],
        "end": [
          11,
          14
        ]
      }
    },
    {
      "file": "static_bad.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "static_bad.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

Needs review: Diagnostics changed for this example

The base and PR report different diagnostics for the same example. Is this change intended?

Reproduction and observed results

Create these files in an empty directory:

main.py

from typing import Callable, overload
from typing_extensions import assert_type
reveal_type(0)
class Wrapper:
    value: str = 'ready'
    @overload
    def __call__(self, owner: type[int], x: int) -> int: ...
    @overload
    def __call__(self, owner: type[object], x: str) -> str: ...
    def __call__(self, owner: type[object], x: int | str) -> int | str:
        return x
def decorate(f: Callable[..., object]) -> Wrapper:
    return Wrapper()
class A:
    @classmethod
    @decorate
    def method(cls, x: object) -> object:
        return x
assert_type(A.method.value, str)
A.method.value.upper()

pyrightconfig.json

{"include":["main.py"],"pythonVersion":"3.13","typeCheckingMode":"basic"}

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 0,
  "diagnostics": [
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "main.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"method\" for class \"type[A]\"\n  No overloads for \"__get__\" match the provided arguments\n  Argument of type \"type[A]\" cannot be assigned to parameter \"owner\" of type \"type[int]\" in function \"__get__\"\n    \"type[A]\" is not assignable to \"type[int]\"\n    Type \"type[A]\" is not assignable to type \"type[int]\"",
      "range": {
        "start": [
          18,
          14
        ],
        "end": [
          18,
          20
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"method\" for class \"type[A]\"\n  No overloads for \"__get__\" match the provided arguments\n  Argument of type \"type[A]\" cannot be assigned to parameter \"owner\" of type \"type[int]\" in function \"__get__\"\n    \"type[A]\" is not assignable to \"type[int]\"\n    Type \"type[A]\" is not assignable to type \"type[int]\"",
      "range": {
        "start": [
          19,
          2
        ],
        "end": [
          19,
          8
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "error",
      "rule": "reportAssertTypeFailure",
      "message": "\"assert_type\" mismatch: expected \"str\" but received \"Unknown\"",
      "range": {
        "start": [
          18,
          12
        ],
        "end": [
          18,
          26
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

Additional reproduction: Diagnostics changed for this example

The base and PR report different diagnostics for the same example. Is this change intended?

Create these files in an empty directory:

control.py

from typing import Callable, overload
from typing_extensions import assert_type
reveal_type(0)
class Wrapper:
    value: str = 'ready'
    @overload
    def __call__(self, owner: type[object], x: str) -> str: ...
    @overload
    def __call__(self, owner: type[int], x: int) -> int: ...
    def __call__(self, owner: type[object], x: int | str) -> int | str:
        return x
def decorate(f: Callable[..., object]) -> Wrapper:
    return Wrapper()
class A:
    @classmethod
    @decorate
    def method(cls, x: object) -> object:
        return x
assert_type(A.method.value, str)
assert_type(A().method.value, str)
assert_type(A.method('s'), str)
A.method.value.upper()

instance.py

from typing import Callable, overload
from typing_extensions import assert_type
reveal_type(0)
class Wrapper:
    value: str = 'ready'
    @overload
    def __call__(self, owner: type[int], x: int) -> int: ...
    @overload
    def __call__(self, owner: type[object], x: str) -> str: ...
    def __call__(self, owner: type[object], x: int | str) -> int | str:
        return x
def decorate(f: Callable[..., object]) -> Wrapper:
    return Wrapper()
class A:
    @classmethod
    @decorate
    def method(cls, x: object) -> object:
        return x
assert_type(A().method.value, str)
A().method.value.upper()

negative.py

from typing import Callable, overload
from typing_extensions import assert_type
reveal_type(0)
class Wrapper:
    value: str = 'ready'
    @overload
    def __call__(self, owner: type[object], x: str) -> str: ...
    @overload
    def __call__(self, owner: type[int], x: int) -> int: ...
    def __call__(self, owner: type[object], x: int | str) -> int | str:
        return x
def decorate(f: Callable[..., object]) -> Wrapper:
    return Wrapper()
class A:
    @classmethod
    @decorate
    def method(cls, x: object) -> object:
        return x
A.method.value.bit_length()
A.method(1)

pyrightconfig.json

{"include":["instance.py","subclass.py","super.py","control.py","negative.py"],"pythonVersion":"3.13","typeCheckingMode":"basic"}

subclass.py

from typing import Callable, overload
from typing_extensions import assert_type
reveal_type(0)
class Wrapper:
    value: str = 'ready'
    @overload
    def __call__(self, owner: type[int], x: int) -> int: ...
    @overload
    def __call__(self, owner: type[object], x: str) -> str: ...
    def __call__(self, owner: type[object], x: int | str) -> int | str:
        return x
def decorate(f: Callable[..., object]) -> Wrapper:
    return Wrapper()
class A:
    @classmethod
    @decorate
    def method(cls, x: object) -> object:
        return x
class B(A):
    pass
assert_type(B.method.value, str)
assert_type(B().method.value, str)
B().method.value.upper()

super.py

from typing import Callable, overload
from typing_extensions import assert_type
reveal_type(0)
class Wrapper:
    value: str = 'ready'
    @overload
    def __call__(self, owner: type[int], x: int) -> int: ...
    @overload
    def __call__(self, owner: type[object], x: str) -> str: ...
    def __call__(self, owner: type[object], x: int | str) -> int | str:
        return x
def decorate(f: Callable[..., object]) -> Wrapper:
    return Wrapper()
class A:
    @classmethod
    @decorate
    def method(cls, x: object) -> object:
        return x
class B(A):
    @classmethod
    def consumer(cls) -> str:
        return super().method.value.upper()
assert_type(B.consumer(), str)

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "control.py",
      "severity": "error",
      "rule": "reportCallIssue",
      "message": "No overloads for \"__call__\" match the provided arguments\n  Argument types: (Literal['s'])",
      "range": {
        "start": [
          20,
          12
        ],
        "end": [
          20,
          25
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "error",
      "rule": "reportAssertTypeFailure",
      "message": "\"assert_type\" mismatch: expected \"str\" but received \"Unknown\"",
      "range": {
        "start": [
          20,
          12
        ],
        "end": [
          20,
          25
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "negative.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"bit_length\" for class \"str\"\n  Attribute \"bit_length\" is unknown",
      "range": {
        "start": [
          18,
          15
        ],
        "end": [
          18,
          25
        ]
      }
    },
    {
      "file": "negative.py",
      "severity": "error",
      "rule": "reportCallIssue",
      "message": "No overloads for \"__call__\" match the provided arguments\n  Argument types: (Literal[1])",
      "range": {
        "start": [
          19,
          0
        ],
        "end": [
          19,
          11
        ]
      }
    },
    {
      "file": "negative.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "super.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"method\" for class \"A\"\n  No overloads for \"__get__\" match the provided arguments\n  Argument of type \"A\" cannot be assigned to parameter \"instance\" of type \"None\" in function \"__get__\"\n    \"A\" is not assignable to \"None\"\n  Argument of type \"type[A]\" cannot be assigned to parameter \"owner\" of type \"type[int]\" in function \"__get__\"\n    \"type[A]\" is not assignable to \"type[int]\"\n    Type \"type[A]\" is not assignable to type \"type[int]\"",
      "range": {
        "start": [
          18,
          16
        ],
        "end": [
          18,
          22
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"method\" for class \"A\"\n  No overloads for \"__get__\" match the provided arguments\n  Argument of type \"A\" cannot be assigned to parameter \"instance\" of type \"None\" in function \"__get__\"\n    \"A\" is not assignable to \"None\"\n  Argument of type \"type[A]\" cannot be assigned to parameter \"owner\" of type \"type[int]\" in function \"__get__\"\n    \"type[A]\" is not assignable to \"type[int]\"\n    Type \"type[A]\" is not assignable to type \"type[int]\"",
      "range": {
        "start": [
          19,
          4
        ],
        "end": [
          19,
          10
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "error",
      "rule": "reportAssertTypeFailure",
      "message": "\"assert_type\" mismatch: expected \"str\" but received \"Unknown\"",
      "range": {
        "start": [
          18,
          12
        ],
        "end": [
          18,
          28
        ]
      }
    },
    {
      "file": "negative.py",
      "severity": "error",
      "rule": "reportArgumentType",
      "message": "Argument of type \"Literal[1]\" cannot be assigned to parameter \"x\" of type \"str\" in function \"__call__\"\n  \"Literal[1]\" is not assignable to \"str\"",
      "range": {
        "start": [
          19,
          9
        ],
        "end": [
          19,
          10
        ]
      }
    },
    {
      "file": "negative.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"bit_length\" for class \"str\"\n  Attribute \"bit_length\" is unknown",
      "range": {
        "start": [
          18,
          15
        ],
        "end": [
          18,
          25
        ]
      }
    },
    {
      "file": "negative.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"method\" for class \"B\"\n  No overloads for \"__get__\" match the provided arguments\n  Argument of type \"B\" cannot be assigned to parameter \"instance\" of type \"None\" in function \"__get__\"\n    \"B\" is not assignable to \"None\"\n  Argument of type \"type[B]\" cannot be assigned to parameter \"owner\" of type \"type[int]\" in function \"__get__\"\n    \"type[B]\" is not assignable to \"type[int]\"\n    Type \"type[B]\" is not assignable to type \"type[int]\"",
      "range": {
        "start": [
          21,
          16
        ],
        "end": [
          21,
          22
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"method\" for class \"B\"\n  No overloads for \"__get__\" match the provided arguments\n  Argument of type \"B\" cannot be assigned to parameter \"instance\" of type \"None\" in function \"__get__\"\n    \"B\" is not assignable to \"None\"\n  Argument of type \"type[B]\" cannot be assigned to parameter \"owner\" of type \"type[int]\" in function \"__get__\"\n    \"type[B]\" is not assignable to \"type[int]\"\n    Type \"type[B]\" is not assignable to type \"type[int]\"",
      "range": {
        "start": [
          22,
          4
        ],
        "end": [
          22,
          10
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"method\" for class \"type[B]\"\n  No overloads for \"__get__\" match the provided arguments\n  Argument of type \"type[B]\" cannot be assigned to parameter \"owner\" of type \"type[int]\" in function \"__get__\"\n    \"type[B]\" is not assignable to \"type[int]\"\n    Type \"type[B]\" is not assignable to type \"type[int]\"",
      "range": {
        "start": [
          20,
          14
        ],
        "end": [
          20,
          20
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "error",
      "rule": "reportAssertTypeFailure",
      "message": "\"assert_type\" mismatch: expected \"str\" but received \"Unknown\"",
      "range": {
        "start": [
          20,
          12
        ],
        "end": [
          20,
          26
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "error",
      "rule": "reportAssertTypeFailure",
      "message": "\"assert_type\" mismatch: expected \"str\" but received \"Unknown\"",
      "range": {
        "start": [
          21,
          12
        ],
        "end": [
          21,
          28
        ]
      }
    },
    {
      "file": "super.py",
      "severity": "error",
      "rule": "reportAttributeAccessIssue",
      "message": "Cannot access attribute \"method\" for class \"type[A]\"\n  No overloads for \"__get__\" match the provided arguments\n  Argument of type \"type[Self@B]\" cannot be assigned to parameter \"owner\" of type \"type[int]\" in function \"__get__\"\n    \"type[B]*\" is not assignable to \"type[int]\"\n    Type \"type[Self@B]\" is not assignable to type \"type[int]\"",
      "range": {
        "start": [
          21,
          23
        ],
        "end": [
          21,
          29
        ]
      }
    },
    {
      "file": "super.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

Needs review: reportCallIssue no longer reported

The base reports reportCallIssue for this example; the PR does not. Is this change intended?

Reproduction and observed results

Create these files in an empty directory:

control.py

from support import decorate
from typing_extensions import assert_type, assert_never, Never
reveal_type(0)
class A:
    @staticmethod
    @decorate
    def method(x: int) -> int:
        return x
assert_type(A.method(1), int)
assert_type(A().method(1), int)
def bottom(x: Never) -> None:
    assert_never(x)

main.py

from support import decorate
reveal_type(0)
class A:
    @classmethod
    @staticmethod
    @decorate
    def method(cls, x: int) -> int:
        return x
A.method(1)

pyrightconfig.json

{"include":["main.py","control.py"],"pythonVersion":"3.8","typeCheckingMode":"basic"}

support.pyi

from typing import Callable, Protocol, TypeVar
from typing_extensions import ParamSpec
P = ParamSpec('P')
R = TypeVar('R', covariant=True)
class Wrapper(Protocol[P, R]):
    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
def decorate(f: Callable[P, R]) -> Wrapper[P, R]: ...

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "control.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "error",
      "rule": "reportCallIssue",
      "message": "Argument missing for parameter \"x\"",
      "range": {
        "start": [
          8,
          0
        ],
        "end": [
          8,
          11
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "warning",
      "rule": "reportSelfClsParameterName",
      "message": "Static methods should not take a \"self\" or \"cls\" parameter",
      "range": {
        "start": [
          6,
          15
        ],
        "end": [
          6,
          18
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 0,
  "diagnostics": [
    {
      "file": "control.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "control.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          2,
          12
        ],
        "end": [
          2,
          13
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "warning",
      "rule": "reportSelfClsParameterName",
      "message": "Static methods should not take a \"self\" or \"cls\" parameter",
      "range": {
        "start": [
          6,
          15
        ],
        "end": [
          6,
          18
        ]
      }
    },
    {
      "file": "main.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

Additional reproduction: reportCallIssue no longer reported

The base reports reportCallIssue for this example; the PR does not. Is this change intended?

Create these files in an empty directory:

alias.py

from support import decorate
reveal_type(0)
cm = classmethod
sm = staticmethod
class A:
    @cm
    @sm
    @decorate
    def method(cls, x: int) -> int:
        return x
A().method(1)

instance.py

from support import decorate
reveal_type(0)
class A:
    @classmethod
    @staticmethod
    @decorate
    def method(cls, x: int) -> int:
        return x
A().method(1)

pyrightconfig.json

{"include":["instance.py","subclass.py","alias.py"],"pythonVersion":"3.8","typeCheckingMode":"basic"}

subclass.py

from support import decorate
reveal_type(0)
class A:
    @classmethod
    @staticmethod
    @decorate
    def method(cls, x: int) -> int:
        return x
class B(A): pass
B.method(1)

support.pyi

from typing import Callable, Protocol, TypeVar
from typing_extensions import ParamSpec
P = ParamSpec('P')
R = TypeVar('R', covariant=True)
class Wrapper(Protocol[P, R]):
    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
def decorate(f: Callable[P, R]) -> Wrapper[P, R]: ...

From that directory, run each built Pyright revision:

node <pyright-cli-entrypoint> --outputjson -p .

Base d4b91d37b21ac7c79390a91586ac0fbfd12886d3

{
  "exit_code": 1,
  "diagnostics": [
    {
      "file": "alias.py",
      "severity": "error",
      "rule": "reportCallIssue",
      "message": "Argument missing for parameter \"x\"",
      "range": {
        "start": [
          10,
          0
        ],
        "end": [
          10,
          13
        ]
      }
    },
    {
      "file": "alias.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "alias.py",
      "severity": "warning",
      "rule": "reportSelfClsParameterName",
      "message": "Static methods should not take a \"self\" or \"cls\" parameter",
      "range": {
        "start": [
          8,
          15
        ],
        "end": [
          8,
          18
        ]
      }
    },
    {
      "file": "alias.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "error",
      "rule": "reportCallIssue",
      "message": "Argument missing for parameter \"x\"",
      "range": {
        "start": [
          8,
          0
        ],
        "end": [
          8,
          13
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "warning",
      "rule": "reportSelfClsParameterName",
      "message": "Static methods should not take a \"self\" or \"cls\" parameter",
      "range": {
        "start": [
          6,
          15
        ],
        "end": [
          6,
          18
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "error",
      "rule": "reportCallIssue",
      "message": "Argument missing for parameter \"x\"",
      "range": {
        "start": [
          9,
          0
        ],
        "end": [
          9,
          11
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "warning",
      "rule": "reportSelfClsParameterName",
      "message": "Static methods should not take a \"self\" or \"cls\" parameter",
      "range": {
        "start": [
          6,
          15
        ],
        "end": [
          6,
          18
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    }
  ]
}

PR e6adb4960ef8e3c981acd43627b72dd0d8274d17

{
  "exit_code": 0,
  "diagnostics": [
    {
      "file": "alias.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "alias.py",
      "severity": "warning",
      "rule": "reportSelfClsParameterName",
      "message": "Static methods should not take a \"self\" or \"cls\" parameter",
      "range": {
        "start": [
          8,
          15
        ],
        "end": [
          8,
          18
        ]
      }
    },
    {
      "file": "alias.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "warning",
      "rule": "reportSelfClsParameterName",
      "message": "Static methods should not take a \"self\" or \"cls\" parameter",
      "range": {
        "start": [
          6,
          15
        ],
        "end": [
          6,
          18
        ]
      }
    },
    {
      "file": "instance.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "warning",
      "rule": "reportMissingModuleSource",
      "message": "Import \"support\" could not be resolved from source",
      "range": {
        "start": [
          0,
          5
        ],
        "end": [
          0,
          12
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "warning",
      "rule": "reportSelfClsParameterName",
      "message": "Static methods should not take a \"self\" or \"cls\" parameter",
      "range": {
        "start": [
          6,
          15
        ],
        "end": [
          6,
          18
        ]
      }
    },
    {
      "file": "subclass.py",
      "severity": "information",
      "rule": null,
      "message": "Type of \"0\" is \"Literal[0]\"",
      "range": {
        "start": [
          1,
          12
        ],
        "end": [
          1,
          13
        ]
      }
    }
  ]
}

Diagnostic ranges use zero-based line and character positions.

@JackyHsu-X

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@JackyHsu-X

Copy link
Copy Markdown
Author

Addressed both QA regressions in ef7592d.

The two diagnostics changes are unintended regressions. Both reproduce on the initial commit d394860: the overloaded staticmethod example reports three errors, and the generic wrapper attribute example reports one.

The follow-up preserves the original wrapper when accessing a staticmethod, keeping its full overload set, and specializes the saved wrapper in the declaring class context so its attributes receive the class type arguments. Classmethod binding continues to use the descriptor's bound call signature.

The existing regression sample now covers overloaded staticmethod access through the class and an instance; int/str generic wrapper attributes; classmethod attributes; inherited access; and invalid overload and generic arguments.

Validation:

  • Both exact CLI QA examples now report zero errors and retain the expected str return and int attribute.
  • The expanded regression fails on d394860 (18 diagnostics instead of 7 expected invalid-call diagnostics) and passes with the follow-up.
  • The original Tenacity, independent protocol, wrapper-attribute, and generic identity CLI checks still pass.
  • Complete Jest suite: 3,516 passed, 12 skipped (97 suites passed, 1 skipped). Used the repository-supported PYLANCE_JEST_TRANSPILE_ONLY=1 mode with separate TypeScript checks.
  • pnpm run typecheck passed for all three workspace packages. pnpm run check and git diff --cached --check passed.

@JackyHsu-X

Copy link
Copy Markdown
Author

The two classmethod regressions in the updated QA report reproduce on ef7592d: the overloaded example reports three errors and the method-generic ParamSpec example reports five. Both now report zero errors in the local follow-up, with the return type correctly inferred as str.

The previous implementation used the built-in classmethod descriptor's inferred single callable signature and then synthesized a replacement __call__. This loses overloads and method-scoped generic information. The revision binds the owning class to each original wrapper call signature using the existing method-specialization machinery, retaining overloads, ParamSpec/TypeVar scope, and wrapper attributes.

The regression sample now checks the two descriptor-protocol cases through both class and instance access, wrapper attributes, overload rejection, and missing/incorrect positional and keyword arguments for generic calls. Its final 12 diagnostics correspond only to deliberately invalid calls; the same sample reports 23 diagnostics with ef7592d.

Validation:

  • The focused regression and all nine CLI probes pass, including both QA rounds, original Tenacity and metadata checks, generic identity, inherited Self, and protocols without descriptors.
  • Complete Jest suite: 3,516 passed, 12 skipped (97 suites passed, 1 skipped), exit code 0. Used the repository-supported PYLANCE_JEST_TRANSPILE_ONLY=1 mode with separate TypeScript checks.
  • pnpm run typecheck passes for all three workspace packages; pnpm run check passes for syncpack, ESLint and Prettier.
  • git diff --cached --check passes.

@JackyHsu-X

Copy link
Copy Markdown
Author

Addressed in b73c29e.

The Python 3.11 descriptor example is an unintended regression: it reports six errors on 1f75b95. The local revision reports zero errors and reveals Example.method as (str) -> str.

The previous classmethod handling always bound the wrapped object's original __call__, overriding a custom descriptor's return type. Python 3.9 through 3.12 delegate to that object's __get__ instead. The revision reuses the existing descriptor-access evaluator and passes the owner class as both obj and owner. Python 3.8 and 3.13+ retain the original callable-binding path. Version boundaries follow the Python documentation.

The new regression covers five target versions, class and instance access, inheritance, the generic owner type, the returned object's attributes, and rejection of an argument valid only for the other binding mode. On 1f75b95, the three delegation-version cases report 18 errors instead of the one deliberately invalid call; the Python 3.8 and 3.13 controls pass. All five pass with the revision, alongside the earlier decorator regression.

Validation:

  • Thirteen built CLI probes report zero errors, including the exact QA example, the earlier two QA rounds, Tenacity, wrapper metadata, generic identity, descriptor overloads/ParamSpec in Python 3.11, and additional custom-descriptor cases.
  • Three workspace packages pass TypeScript checking; syncpack, ESLint, Prettier, and git diff --check pass.
  • The exact runtime example also completes successfully on the available Python 3.12.8 runtime. Python 3.11 behavior was checked as a target version, not by installing another interpreter.
  • Complete Jest suite: 3,521 passed, 12 skipped (97 suites passed, 1 skipped), exit code 0. Used the repository-supported PYLANCE_JEST_TRANSPILE_ONLY=1 mode with separate TypeScript checks.

AI assistance was used to investigate the regression, implement the patch, and run validation.

@JackyHsu-X

Copy link
Copy Markdown
Author

Addressed in e822d6b.

The double-classmethod diagnostics are unintended. The exact Python 3.12 QA case reports three errors on b73c29e; the revision reports zero and retains the original Wrapper type for both class and instance access.

Python 3.9 through 3.12 delegate a classmethod access to the wrapped descriptor. If that descriptor is another built-in classmethod, it receives the same owner and produces the same binding as the inner layer. The revision preserves that inner descriptor before ordinary callable validation, rather than trying to validate the noncallable classmethod object as a function. The shortcut is limited to the two built-in classmethod types and the supported version range.

The new regression covers two and three layers, inherited access, generic type arguments and wrapper attributes, a custom wrapped descriptor returning a different signature, and incorrect or missing arguments. On the published source, the 3.9/3.11/3.12 cases each report 28 errors instead of four intentional errors; the 3.8/3.13 controls pass. All five pass with the fix, and CLI checks verify that only the intended lines produce errors.

Validation:

  • Exact latest QA and all preceding probes: 14 CLI cases report zero errors.
  • Decorator8/9/10 focused tests: 11 passed.
  • Three workspace packages pass TypeScript checking; syncpack, ESLint, Prettier and diff checks pass.
  • Actual Python 3.11.16/3.12.8 probes confirm the nesting and owner-binding behavior; Python 3.14.3 confirms that nested classmethods no longer delegate. Other version boundaries are static targets.
  • Complete Jest suite: 3,526 passed, 12 skipped (97 suites passed, 1 skipped), exit code 0. Used the supported transpile-only test mode with separate TypeScript checking.

AI assistance was used to investigate, implement and validate the revision.

@bschnurr

Copy link
Copy Markdown
Member

Local review: e822d6b2 integrated with ff00b031.

All 18 focused decorator tests passed, including the version-specific fixtures that fail on main. The older Python 3.12 double-classmethod QA case no longer reproduces: both class and instance attribute accesses are accepted.

@JackyHsu-X

Copy link
Copy Markdown
Author

Addressed the four Python 3.9 cases in e6adb49. The diagnostic changes were unintended. CPython 3.9 passes (cls, None) to the wrapped descriptor's __get__, while 3.10–3.12 pass (cls, cls). Using the latter arguments for 3.9 rejected the valid overload in cases 1–3 and selected the wrong overload in case 4.

The fix models those version-specific arguments and follows the receiver's metaclass at each additional built-in classmethod layer when delegating to a custom descriptor in Python 3.9.

I reproduced all four reports on e822d6b2. With the fix, cases 1–3 report no errors and case 4 reports only the expected invalid integer argument in negative.py. The 14 previous CLI probes and 13 focused tests also pass. The complete local Jest suite finished with 3,528 passed and 12 skipped, and workspace TypeScript and static checks passed.

Python 3.9 behavior was checked against the CPython source and in Pyright's 3.9 target mode. Runtime probes ran on installed CPython 3.10–3.13. AI assistance was used to investigate, implement, and validate the fix.

This branch has not been deployed

No deployments
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.

3 participants