Skip to content

Preserve union-expanded constructor types - #11621

Merged
Rich Chiodo (rchiodo) merged 3 commits into
mainfrom
rchiodo-preserve-constructor-union-types
Aug 11, 2026
Merged

Rich Chiodo (rchiodo) merged 3 commits into
mainfrom
rchiodo-preserve-constructor-union-types

Conversation

@rchiodo

Copy link
Copy Markdown
Collaborator

Summary

  • accumulate each union-expanded overloaded __init__ branch's effective specialized self type, including definitive and single-possible branches
  • reconstruct union-valued constructor handoffs subtype-by-subtype so gradual members and concrete constructed types are all preserved
  • add focused coverage for mixed ambiguous/definitive branches, all-ambiguous branches, definitive constructor unions, explicit specialization, and the None __init__ placeholder

Follow-up to #11601. This addresses the unresolved review finding in #11601 (comment), where a later definitive branch such as Table[bytes] was omitted once an earlier materialization-ambiguous branch populated the separate constructor handoff.

Tests

  • npx jest typeEvaluator6.test -t "OverloadCall12" --runInBand --forceExit
  • npx jest typeEvaluator6.test -t "OverloadCall(6|11|12)|Constructor" --runInBand --forceExit
  • npm run build (packages/pyright-internal)
  • npm run typecheck
  • focused ESLint and Prettier checks for changed TypeScript files

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@StellaHuang95

Copy link
Copy Markdown
Collaborator

🔒 Automated review in progress — Stella Huang (@StellaHuang95) is auto-reviewing this PR.

@github-actions

This comment has been minimized.

@StellaHuang95 Stella Huang (StellaHuang95) added the review-auto:changes-requested Automated review: posted blocking findings to address. label Aug 11, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@StellaHuang95

Copy link
Copy Markdown
Collaborator

GitHub cannot anchor PR review comments to unchanged lines in the diff. Falling back to a general PR comment for packages/pyright-internal/src/tests/samples/overloadCall12.py:L227.

Warning · Non-blocking recommendation

Add coverage for a union of two definitive branches that both rely only on the boundToType fallback, such as set[int] | set[float] through the non-self:-annotated set[_T] overload. The current cases trigger either ambiguity or a raw specializedInitSelfType, so they do not exercise the combine-gate gap.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved via Review Center.

@StellaHuang95 Stella Huang (StellaHuang95) added review-auto:approved Automated review: no blocking findings (approval posted). and removed review-auto:changes-requested Automated review: posted blocking findings to address. labels Aug 11, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

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

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 | Mul | Basic" and "Literal[2]"
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:309:10 - error: Operator "+" not supported for types "Expr" and "Unknown | Expr | Mul | None"
-     Operator "+" not supported for types "Expr" and "None" (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"
-     Operator "*" not supported for types "MPZ" and "Expr" (reportOperatorIssue)
-   .../projects/sympy/sympy/simplify/sqrtdenest.py:635:50 - 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 "Mul | Expr"
-     Operator "*" not supported for types "GaussianRational" and "Mul"
-     Operator "*" not supported for types "GaussianRational" and "Expr"

... (truncated 626 lines) ...

bidict (https://github.com/jab/bidict)
- .../projects/bidict/bidict/_base.py
-   .../projects/bidict/bidict/_base.py:550:34 - error: No overloads for "__init__" match the provided arguments (reportCallIssue)
-   .../projects/bidict/bidict/_base.py:550:39 - error: Argument of type "BidictBase[VT@BidictBase, KT@BidictBase]*" cannot be assigned to parameter "map" of type "SupportsKeysAndGetItem[_KT@dict, _VT@dict]" in function "__init__"
-     "BidictBase[VT@BidictBase, KT@BidictBase]*" is incompatible with protocol "SupportsKeysAndGetItem[_KT@dict, _VT@dict]"
-       Type parameter "_KT@SupportsKeysAndGetItem" is invariant, but "VT@BidictBase" is not the same as "_KT@dict" (reportArgumentType)
-   .../projects/bidict/bidict/_base.py:550:39 - error: Argument of type "BidictBase[VT@BidictBase, KT@BidictBase]* | Self@BidictBase[KT@BidictBase, VT@BidictBase]" cannot be assigned to parameter "iterable" of type "Iterable[list[bytes]]" in function "__init__"
-     Type "BidictBase[VT@BidictBase, KT@BidictBase]* | BidictBase[KT@BidictBase, VT@BidictBase]*" is not assignable to type "Iterable[list[bytes]]"
-       "BidictBase[KT@BidictBase, VT@BidictBase]*" is not assignable to "Iterable[list[bytes]]"
-         Type parameter "_T_co@Iterable" is covariant, but "KT@BidictBase" is not a subtype of "list[bytes]"
-           "object*" is not assignable to "list[bytes]" (reportArgumentType)
- 8 errors, 1 warning, 0 informations
+ 5 errors, 1 warning, 0 informations

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved via Review Center.

@rchiodo
Rich Chiodo (rchiodo) merged commit 27001c2 into main Aug 11, 2026
20 checks passed
Rich Chiodo (rchiodo) added a commit that referenced this pull request Sep 11, 2026
…11739)

* Revert nested overload materialization and dependent checker fixes

Selectively roll back #11601, #11621, and checker-only #11732 while preserving primer-analysis tooling and independent subsequent fixes. Retain regression fixtures and document the restored conformance, constructor, and protocol-operation limitations in current-behavior expectations.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Restore matching gh-aw compiler and runtime for primer analysis

Regenerate with v0.86.2, preserve current artifact action versions, and prevent standalone runtime bumps with a narrow Dependabot ignore and workflow consistency coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Preserve constructor constraints and results across union branches

Replay each expanded argument using its own overload constraints and retain definitive constructed union branches. Fix the reproduced Werkzeug Mapping-to-dict regression without restoring nested overload materialization, and retain precise positive and negative regression coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

2 participants