Repository navigation
Allow assigning signature metadata to functions - #11714
Rich Chiodo (rchiodo) merged 3 commits into
Conversation
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.
|
@microsoft-github-policy-service agree |
|
🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR. |
|
Result: 🔴 Verification detailsVerification: 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
|
Bill Schnurr (bschnurr)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
|
Thanks for the review and approval. The verification report identifies environment failures ( The requested regression command has now been rerun successfully on the unchanged PR head node ./node_modules/jest/bin/jest.js typeEvaluator1.test -t "FunctionMember1|FunctionMember2" --runInBand --forceExitResult: 1 suite passed; 2 tests passed, 158 skipped. 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? |
|
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
|
Fixes #11435.
Pyright currently reports
reportFunctionMemberAccessfor 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.FunctionTypevalues, and the Python-implementedtyping.casthelper.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:
typeEvaluator1.test.ts: 160 passed.git diff --check: passed.