Repository navigation
Fix binding for callable protocol method decorators - #11875
Jacky Hsu (JackyHsu-X) wants to merge 6 commits into
Conversation
🔴 Pyright CLI QA —
|
|
@microsoft-github-policy-service agree |
|
Addressed both QA regressions in The two diagnostics changes are unintended regressions. Both reproduce on the initial commit 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; Validation:
|
|
The two classmethod regressions in the updated QA report reproduce on The previous implementation used the built-in classmethod descriptor's inferred single callable signature and then synthesized a replacement 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 Validation:
|
|
Addressed in The Python 3.11 descriptor example is an unintended regression: it reports six errors on The previous classmethod handling always bound the wrapped object's original 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 Validation:
AI assistance was used to investigate the regression, implement the patch, and run validation. |
|
Addressed in The double-classmethod diagnostics are unintended. The exact Python 3.12 QA case reports three errors on 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:
AI assistance was used to investigate, implement and validate the revision. |
|
Local review: All 18 focused decorator tests passed, including the version-specific fixtures that fail on |
|
Addressed the four Python 3.9 cases in The fix models those version-specific arguments and follows the receiver's metaclass at each additional built-in I reproduced all four reports on 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. |
@classmethodcurrently leaves a callable object returned by an inner decorator unchanged. A normal call such asExample.method(1)then retains theclsparameter and reports a missing argument.@staticmethodsimilarly 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, andretry_withkeep 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:
b73c29e; the revision reports zero and preserves the original wrapper type for class and instance access.b73c29efor 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.PYLANCE_JEST_TRANSPILE_ONLY=1mode with separate TypeScript checking.pnpm run typecheckpasses for all three checked workspace packages.pnpm run checkpasses syncpack, ESLint and Prettier;git diff --checkpasses.AI assistance was used to investigate the issue, implement the patch, and run validation.