Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes #1687

Now synthesize a constructor-backed __call__ attribute for class objects (including the magic-dunder fast path), so protocol/ParamSpec checks see the actual constructor signature instead of the permissive type.__call__, letting kwargs mismatches surface.

Test Plan

Adds a regression test covering the FastAPI-style middleware helper to lock in the new error behavior.

@meta-cla meta-cla bot added the cla signed label Dec 4, 2025
@asukaminato0721 asukaminato0721 marked this pull request as ready for review December 4, 2025 12:12
Copilot AI review requested due to automatic review settings December 4, 2025 12:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #1687 by ensuring that ParamSpec-based protocol checks can detect extra keyword arguments when checking class constructors. The fix synthesizes a __call__ attribute for class objects that exposes the actual constructor signature (derived from __new__/__init__) instead of falling back to the permissive type.__call__.

Key Changes:

  • Synthesizes constructor-backed __call__ attribute for class objects during attribute lookup
  • Applies to both the magic dunder fast path and regular class object attribute lookup
  • Enables proper signature validation for ParamSpec protocols like middleware factories

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pyrefly/lib/test/paramspec.rs Adds regression test for FastAPI-style middleware pattern to ensure extra kwargs are detected
pyrefly/lib/alt/attr.rs Implements synthetic __call__ attribute synthesis using constructor_to_callable for class objects in both magic dunder and regular attribute lookup paths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yangdanny97
Copy link
Contributor

Where's the location that looks up __call__ to resolve the param spec? It might be easier to change that to look up the constructor type for classes.

@yangdanny97 yangdanny97 self-assigned this Dec 4, 2025
@asukaminato0721 asukaminato0721 marked this pull request as ready for review December 4, 2025 16:33
@meta-codesync
Copy link

meta-codesync bot commented Dec 8, 2025

@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D88641669.

Copy link
Contributor

@ndmitchell ndmitchell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync
Copy link

meta-codesync bot commented Dec 8, 2025

@yangdanny97 merged this pull request in cdab03e.

@yangdanny97
Copy link
Contributor

Thank you!

@asukaminato0721 asukaminato0721 deleted the 1687 branch December 9, 2025 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False negative on extra arguments to paramspec callable

4 participants