Skip to content

Allow assigning signature metadata to functions - #11714

Merged
Rich Chiodo (rchiodo) merged 3 commits into
microsoft:mainfrom
mukeshr06:fix/function-signature-assignments
Sep 8, 2026
Merged

Rich Chiodo (rchiodo) merged 3 commits into
microsoft:mainfrom
mukeshr06:fix/function-signature-assignments

Conversation

@mukeshr06

@mukeshr06 mukeshr06 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11435.

Pyright currently reports reportFunctionMemberAccess for assignments to function __signature__ and __text_signature__, although these metadata attributes are writable on Python function objects.

Allow these two assignments through the existing function-object fallback. Preserve diagnostics for reads, deletes, arbitrary attributes, bound methods, and known functions from builtins, including overloaded builtins. Add coverage for user functions, types.FunctionType values, and the Python-implemented typing.cast helper.

Classification: B (Pyright limitation). Typeshed commit: N/A. This removes false-positive assignment diagnostics without widening inferred types or removing existing precision checks. Stubs for other modules do not reliably identify whether a function is implemented in Python or C; this follows their existing function-object representation.

Validation:

  • The new assignment regression failed before the fix.
  • Complete typeEvaluator1.test.ts: 160 passed.
  • Package build, repository syncpack/ESLint/Prettier checks, and repository typecheck: passed.
  • git diff --check: passed.

Classification: B (Pyright limitation).
Typeshed commit: N/A.
Allow writes to supported function signature metadata without changing inferred types. Keep diagnostics for reads, deletes, arbitrary attributes, known builtins, and bound methods.

This commit updates the implementation. Regression fixtures and expected diagnostic counts follow on this branch before the pull request is opened.
Classification: B (Pyright limitation).
Typeshed commit: N/A.
Cover supported function metadata writes and preserve negative cases for reads, deletes, known builtins, bound methods, and arbitrary attributes.

The corresponding diagnostic-count updates follow in the next commit before the pull request is opened.
Classification: B (Pyright limitation).
Typeshed commit: N/A.
Update expected diagnostic counts for the added function metadata regression cases. This completes the implementation and regression-test patch. No inferred type precision is widened.
@mukeshr06

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@bschnurr

Bill Schnurr (bschnurr) commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR.

@bschnurr

Copy link
Copy Markdown
Member

Result: 🔴 could-not-verify

Verification details

Verification: Isolated verification observed failures that were not classified as caused by this PR: Repository discovery with relative cwd, Repository discovery with explicit worktree cwd. The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Summary: The focused `FunctionMember1` and `FunctionMember2` Jest regressions could not start because the verification image has no Node runtime. Repository discovery also failed because the container did not expose the checkout as a Git worktree. The PR adds comprehensive sample coverage, but no executable verification completed, so confidence is limited.

Test runs: 2 failed, 1 not run

  • ⚠️ Not run | FunctionMember1 and FunctionMember2 regressions | node ./node_modules/jest/bin/jest.js typeEvaluator1.test -t "FunctionMember1|FunctionMember2" --runInBand --forceExit
  • ❌ Failed | unrelated to this PR | Repository discovery with relative cwd | set -eu; printf '%s\n' '--- refs ---'; git --no-pager branch -a --no-color; printf '%s\n' '--- changed files ---'; if git show-ref --verify --quiet refs/remotes/upstream/main; then BASE=upstream/main; elif git show-ref --verify --quiet refs/remotes/origin/main; then BASE=origin/main; else BASE=HEAD^; fi; echo "BASE=$BASE"; git --no-pager diff --name-status "$BASE"...HEAD; printf '%s\n' '--- package runner ---'; test -f packages/pyright-internal/package.json && node -e "const p=require('./packages/pyright-internal/package.json'); console.log(JSON.stringify({scripts:p.scripts},null,2))" | grep -E '"(test|test:norebuild|build|typecheck)' || true; printf '%s\n' '--- dependencies ---'; if test -x packages/pyright-internal/node_modules/.bin/jest || test -f packages/pyright-internal/node_modules/jest/bin/jest.js; then echo 'package jest available'; elif test -f node_modules/jest/bin/jest.js; then echo 'root jest available'; else echo 'jest missing'; fi
  • ❌ Failed | unrelated to this PR | Repository discovery with explicit worktree cwd | set -eu; printf '%s\n' '--- refs ---'; git --no-pager branch -a --no-color; printf '%s\n' '--- changed files ---'; if git show-ref --verify --quiet refs/remotes/upstream/main; then BASE=upstream/main; elif git show-ref --verify --quiet refs/remotes/origin/main; then BASE=origin/main; else BASE=HEAD^; fi; echo "BASE=$BASE"; git --no-pager diff --name-status "$BASE"...HEAD; printf '%s\n' '--- package runner ---'; test -f packages/pyright-internal/package.json && node -e "const p=require('./packages/pyright-internal/package.json'); console.log(JSON.stringify({scripts:p.scripts},null,2))" | grep -E '"(test|test:norebuild|build|typecheck)' || true; printf '%s\n' '--- dependencies ---'; if test -x packages/pyright-internal/node_modules/.bin/jest || test -f packages/pyright-internal/node_modules/jest/bin/jest.js; then echo 'package jest available'; elif test -f node_modules/jest/bin/jest.js; then echo 'root jest available'; else echo 'jest missing'; fi
⚠️ FunctionMember1 and FunctionMember2 regressions diagnostic output
/bin/sh: 1: node: not found
❌ Repository discovery with relative cwd diagnostic output
fatal: not a git repository (or any parent up to mount point /)
❌ Repository discovery with explicit worktree cwd diagnostic output
fatal: not a git repository (or any parent up to mount point /)

@bschnurr Bill Schnurr (bschnurr) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved via Review Center.

@bschnurr Bill Schnurr (bschnurr) added the review-auto:approved Automated review: no blocking findings (approval posted). label Sep 7, 2026
@mukeshr06

Copy link
Copy Markdown
Contributor Author

Thanks for the review and approval. The verification report identifies environment failures (node: not found and the checkout not being recognized as a Git worktree).

The requested regression command has now been rerun successfully on the unchanged PR head 91697b058b482ce04094ee0a360f673ebbd8e94f, using Node v24.19.0 and the pinned pnpm 11.21.0 dependencies. From packages/pyright-internal:

node ./node_modules/jest/bin/jest.js typeEvaluator1.test -t "FunctionMember1|FunctionMember2" --runInBand --forceExit

Result: 1 suite passed; 2 tests passed, 158 skipped. git rev-parse --is-inside-work-tree returned true, and the working tree is clean.

The CLA check is passing. GitHub currently shows two workflows awaiting maintainer approval; could a maintainer approve those runs so the upstream CI can complete?

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

ibis (https://github.com/ibis-project/ibis)
-   .../projects/ibis/ibis/backends/impala/udf.py:50:12 - error: Cannot assign to attribute "__signature__" for class "FunctionType"
-     Attribute "__signature__" is unknown (reportFunctionMemberAccess)
-   .../projects/ibis/ibis/backends/postgres/__init__.py:434:19 - error: Cannot assign to attribute "__signature__" for class "FunctionType"
-     Attribute "__signature__" is unknown (reportFunctionMemberAccess)
- 7201 errors, 257 warnings, 0 informations
+ 7199 errors, 257 warnings, 0 informations

sympy (https://github.com/sympy/sympy)
+   .../projects/sympy/sympy/simplify/sqrtdenest.py:157:19 - error: Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
+   .../projects/sympy/sympy/simplify/sqrtdenest.py:200:48 - error: Argument of type "Basic" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
+     Type "Basic" is not assignable to type "Expr | complex"
+       "Basic" is not assignable to "Expr"
+       "Basic" is not assignable to "complex" (reportArgumentType)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:207:26 - error: Operator "**" not supported for types "Unknown | Self@AssocOp | AssocOp*" and "Literal[2]"
+   .../projects/sympy/sympy/simplify/sqrtdenest.py:207:26 - error: Operator "**" not supported for types "Unknown | Self@AssocOp | Basic | AssocOp*" and "Literal[2]"
+     Operator "**" not supported for types "Basic" and "Literal[2]"
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:288:16 - error: Operator "*" not supported for types "Expr" and "Unknown | None"
+   .../projects/sympy/sympy/simplify/sqrtdenest.py:288:16 - error: Operator "*" not supported for types "Expr" and "Unknown | Expr | None"
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:309:10 - error: Operator "+" not supported for types "Expr" and "Unknown | Expr | Self@AssocOp | None"
-     Operator "+" not supported for types "Expr" and "None"
-     Operator "+" not supported for types "Expr" and "AssocOp*" (reportOperatorIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:340:19 - error: Operator "-" not supported for types "Expr | Unknown | GaussianRational | One | NegativeOne | Zero | Integer | MPQ | GaussianInteger | MPZ | Poly | NotImplementedType | ANP[MPQ]" and "Expr | Unknown | NotImplementedType | GaussianRational | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | MPQ | GaussianInteger | MPZ | Poly"
-     Operator "-" not supported for types "Expr" and "GaussianRational"
-     Operator "-" not supported for types "Expr" and "MPQ"
-     Operator "-" not supported for types "Expr" and "GaussianInteger"
-     Operator "-" not supported for types "Expr" and "MPZ"
-     Operator "-" not supported for types "GaussianRational" and "Expr"
-     Operator "-" not supported for types "GaussianRational" and "NaN"
-     Operator "-" not supported for types "GaussianRational" and "ComplexInfinity"
-     Operator "-" not supported for types "GaussianRational" and "Rational"
-     ... (reportOperatorIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:340:26 - error: Operator "*" not supported for types "Expr | Unknown | GaussianRational | One | NegativeOne | Zero | Integer | MPQ | GaussianInteger | MPZ | Poly | NotImplementedType | ANP[MPQ]" and "Expr | Unknown | NotImplementedType | GaussianRational | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | MPQ | GaussianInteger | MPZ | Infinity | NegativeInfinity | Float | Poly | Alg | Number"
-     Operator "*" not supported for types "Expr" and "GaussianRational"
-     Operator "*" not supported for types "Expr" and "MPQ"
-     Operator "*" not supported for types "Expr" and "GaussianInteger"
-     Operator "*" not supported for types "Expr" and "MPZ"
-     Operator "*" not supported for types "GaussianRational" and "Expr"
-     Operator "*" not supported for types "GaussianRational" and "NaN"
-     Operator "*" not supported for types "GaussianRational" and "ComplexInfinity"
-     Operator "*" not supported for types "GaussianRational" and "Rational"
-     ... (reportOperatorIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:341:11 - error: Cannot access attribute "is_Rational" for class "GaussianRational"
-     Attribute "is_Rational" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:341:11 - error: Cannot access attribute "is_Rational" for class "MPQ"
-     Attribute "is_Rational" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:341:11 - error: Cannot access attribute "is_Rational" for class "GaussianInteger"
-     Attribute "is_Rational" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:341:11 - error: Cannot access attribute "is_Rational" for class "MPZ"
-     Attribute "is_Rational" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:341:11 - error: Cannot access attribute "is_Rational" for class "ANP[MPQ]"
-     Attribute "is_Rational" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:342:15 - error: Cannot access attribute "is_positive" for class "GaussianRational"
-     Attribute "is_positive" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:342:15 - error: Cannot access attribute "is_positive" for class "MPQ"
-     Attribute "is_positive" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:342:15 - error: Cannot access attribute "is_positive" for class "GaussianInteger"
-     Attribute "is_positive" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:342:15 - error: Cannot access attribute "is_positive" for class "MPZ"
-     Attribute "is_positive" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:342:15 - error: Cannot access attribute "is_positive" for class "ANP[MPQ]"
-     Attribute "is_positive" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:350:28 - error: Operator "*" not supported for types "Unknown | Expr | GaussianRational | NegativeOne | One | Zero | Integer | NaN | ComplexInfinity | Rational | NegativeInfinity | Infinity | Float | Number | MPQ | GaussianInteger | MPZ | Poly | ANP[MPQ]" and "Expr | Unknown | NotImplementedType | GaussianRational | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | MPQ | GaussianInteger | MPZ | Infinity | NegativeInfinity | Float | Poly | Alg | Number"
-     Operator "*" not supported for types "Expr" and "GaussianRational"
-     Operator "*" not supported for types "Expr" and "MPQ"
-     Operator "*" not supported for types "Expr" and "GaussianInteger"
-     Operator "*" not supported for types "Expr" and "MPZ"
-     Operator "*" not supported for types "GaussianRational" and "Expr"
-     Operator "*" not supported for types "GaussianRational" and "NaN"
-     Operator "*" not supported for types "GaussianRational" and "ComplexInfinity"
-     Operator "*" not supported for types "GaussianRational" and "Rational"
-     ... (reportOperatorIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:353:51 - error: Operator "*" not supported for types "Expr | Unknown | NotImplementedType | GaussianRational | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | MPQ | GaussianInteger | MPZ | Infinity | NegativeInfinity | Float | Poly | Alg | Number" and "Expr | Unknown | NotImplementedType | GaussianRational | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | MPQ | GaussianInteger | MPZ | Infinity | NegativeInfinity | Float | Poly | Alg | Number"
-     Operator "*" not supported for types "Expr" and "GaussianRational"
-     Operator "*" not supported for types "Expr" and "MPQ"
-     Operator "*" not supported for types "Expr" and "GaussianInteger"
-     Operator "*" not supported for types "Expr" and "MPZ"
-     Operator "*" not supported for types "GaussianRational" and "Expr"
-     Operator "*" not supported for types "GaussianRational" and "NaN"
-     Operator "*" not supported for types "GaussianRational" and "ComplexInfinity"
-     Operator "*" not supported for types "GaussianRational" and "Rational"
-     ... (reportOperatorIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:431:42 - error: Operator "-" not supported for types "Expr" and "Expr | Unknown | NotImplementedType | GaussianRational | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | MPQ | GaussianInteger | MPZ | Infinity | NegativeInfinity | Float | Poly | Alg | Number"
-     Operator "-" not supported for types "Expr" and "GaussianRational"
-     Operator "-" not supported for types "Expr" and "MPQ"
-     Operator "-" not supported for types "Expr" and "GaussianInteger"
-     Operator "-" not supported for types "Expr" and "MPZ" (reportOperatorIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:597:24 - error: Operator "-" not supported for types "Unknown | One | NegativeOne | Zero | Integer | Expr | None" and "Unknown | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | None"
+   .../projects/sympy/sympy/simplify/sqrtdenest.py:597:24 - error: Operator "-" not supported for types "Expr | Unknown | None" and "Expr | Unknown | None"
-     Operator "-" not supported for types "None" and "NaN"
+     Operator "-" not supported for types "None" and "Expr"
-     Operator "-" not supported for types "None" and "ComplexInfinity"
-     Operator "-" not supported for types "None" and "Rational"
-     Operator "-" not supported for types "None" and "Infinity"
-     Operator "-" not supported for types "None" and "NegativeInfinity"
-     Operator "-" not supported for types "None" and "Float"
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:626:49 - error: Operator "*" not supported for types "Expr | Unknown | GaussianRational | NegativeOne | One | Zero | Integer | NaN | ComplexInfinity | Rational | MPQ | GaussianInteger | MPZ | NegativeInfinity | Infinity | Float | Poly | ANP[MPQ] | Number | NotImplementedType" and "Expr"
-     Operator "*" not supported for types "GaussianRational" and "Expr"
-     Operator "*" not supported for types "MPQ" and "Expr"
-     Operator "*" not supported for types "GaussianInteger" and "Expr"

... (truncated 364 lines) ...

scikit-learn (https://github.com/scikit-learn/scikit-learn)
-   .../projects/scikit-learn/sklearn/utils/_metadata_requests.py:1508:14 - error: Cannot assign to attribute "__signature__" for class "FunctionType"
-     Attribute "__signature__" is unknown (reportFunctionMemberAccess)
- 17191 errors, 466 warnings, 0 informations
+ 17190 errors, 466 warnings, 0 informations

trio (https://github.com/python-trio/trio)
+ .../projects/trio/src/trio/_timeouts.py
+   .../projects/trio/src/trio/_timeouts.py:197:109 - error: Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)
- 1741 errors, 13 warnings, 0 informations
+ 1742 errors, 13 warnings, 0 informations

@rchiodo
Rich Chiodo (rchiodo) merged commit 854df36 into microsoft:main Sep 8, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't raise reportFunctionMemberAccess for __text_signature__ and __signature__ attributes of functions

3 participants