Repository navigation
Retain bounded alternatives for ambiguous overload calls - #11780
Conversation
Preserve complete overload return alternatives and whole-operation witnesses without erasing container precision or losing ordinary diagnostics. Enable bounded lazy activation by default while retaining the internal baseline control and leaving checker live-cache handoff disabled. Carry reviewed regression coverage and documentation onto pinned main, preserving upstream complexity, TypeForm cache, and TypedDict behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR. |
This comment has been minimized.
This comment has been minimized.
|
Please add runtime coverage for the new type-server protocol conversion path; the current targeted tests do not exercise it. |
Bill Schnurr (bschnurr)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
This comment has been minimized.
This comment has been minimized.
Defer cache eviction until the owning file check or outer request unwinds, bind controllers to their own evaluator, and prevent late asynchronous cleanup from recreating a disposed Program. Add regressions for diagnostic completeness, precise overload alternatives, cancellation, and shutdown. Classification: B (Pyright evaluator lifecycle limitation). No typeshed changes or type-precision reductions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Result: ✅ Verification detailsVerification: Isolated verification observed failures that were not classified as caused by this PR: Repository discovery preflight. Summary: Targeted verification passed: 164 tests across overload-result units, controller behavior, configuration, CLI analysis, and language-server paths. The LSP test-server build also succeeded, including foreground/background and push/pull diagnostic cases. Dependencies were restored successfully with the offline frozen lockfile. An initial repository-discovery probe used an invalid empty working directory, but this was unrelated to the PR and did not prevent test execution. Test runs: 4 passed, 1 failed
❌
|
Define the evaluator-owned isolation contract and rename production cache APIs without changing transaction, speculation, or diagnostic semantics. Preserve all existing type expectations and the evaluator lifetime fix. Classification: D (runtime coverage gap). Add real JSON-RPC carrier conversion and nested factory/reference coverage, plus exact-node restoration coverage. No typeshed changes or type-precision regressions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Fixed the runtime protocol-coverage request in ea2db303. Added a real in-process JSON-RPC Both new tests failed when the |
|
Diff from mypy_primer, showing the effect of this PR on open source code: sympy (https://github.com/sympy/sympy)
+ .../projects/sympy/sympy/solvers/bivariate.py:135:15 - error: Operator "-" not supported for "None" (reportOptionalOperand)
+ .../projects/sympy/sympy/solvers/bivariate.py:139:17 - error: Operator "-" not supported for type "Basic | Unknown" (reportOperatorIssue)
+ .../projects/sympy/sympy/solvers/bivariate.py:144:23 - error: Operator "-" not supported for "None" (reportOptionalOperand)
+ .../projects/sympy/sympy/solvers/deutils.py:234:14 - error: Operator "not in" not supported for types "str" and "Unknown | int"
+ Operator "not in" not supported for types "str" and "int" (reportOperatorIssue)
+ .../projects/sympy/sympy/solvers/ode/lie_group.py:619:61 - error: Operator "-" not supported for type "Unknown | Basic" (reportOperatorIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1433:17 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
+ .../projects/sympy/sympy/solvers/ode/ode.py:1433:17 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
- Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Expr" is not assignable to type "Zero"
+ Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" is not assignable to type "Zero"
- .../projects/sympy/sympy/solvers/ode/ode.py:1579:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1580:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1590:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1590:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
- .../projects/sympy/sympy/solvers/ode/ode.py:1590:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
- Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
- "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
- "__iter__" is not present (reportArgumentType)
- .../projects/sympy/sympy/solvers/ode/ode.py:1597:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1597:64 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1603:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1603:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
- .../projects/sympy/sympy/solvers/ode/ode.py:1603:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
- Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
- "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
- "__iter__" is not present (reportArgumentType)
- .../projects/sympy/sympy/solvers/ode/ode.py:1610:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1610:74 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1616:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1616:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
- .../projects/sympy/sympy/solvers/ode/ode.py:1616:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
- Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
- "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
- "__iter__" is not present (reportArgumentType)
- .../projects/sympy/sympy/solvers/ode/ode.py:1623:49 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1623:70 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1753:36 - error: Cannot access attribute "lhs" for class "Expr"
+ Attribute "lhs" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1753:55 - error: Cannot access attribute "rhs" for class "Expr"
+ Attribute "rhs" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1754:36 - error: Cannot access attribute "lhs" for class "Expr"
+ Attribute "lhs" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1755:17 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1755:17 - error: Argument of type "Equality | BooleanFalse | BooleanTrue | Unknown | Expr" cannot be assigned to parameter "value" of type "Equality | BooleanFalse | BooleanTrue" in function "__setitem__"
+ Type "Equality | BooleanFalse | BooleanTrue | Unknown | Expr" is not assignable to type "Equality | BooleanFalse | BooleanTrue"
+ Type "Expr" is not assignable to type "Equality | BooleanFalse | BooleanTrue"
+ "Expr" is not assignable to "Equality"
+ "Expr" is not assignable to "BooleanFalse"
+ "Expr" is not assignable to "BooleanTrue" (reportArgumentType)
- .../projects/sympy/sympy/solvers/ode/ode.py:2961:17 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
+ .../projects/sympy/sympy/solvers/ode/ode.py:2961:17 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
- Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Expr" is not assignable to type "Zero"
+ Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" is not assignable to type "Zero"
- .../projects/sympy/sympy/solvers/ode/ode.py:3442:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
- .../projects/sympy/sympy/solvers/ode/ode.py:3442:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3443:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
- .../projects/sympy/sympy/solvers/ode/ode.py:3443:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3444:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3445:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3446:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3458:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3459:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3460:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3500:5 - error: No overloads for "update" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:3500:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
- .../projects/sympy/sympy/solvers/ode/ode.py:3500:14 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
- Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
- "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
- "__iter__" is not present (reportArgumentType)
- .../projects/sympy/sympy/solvers/ode/ode.py:3501:18 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3501:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3502:9 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3502:16 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3502:24 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:3502:31 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
... (truncated 502 lines) ...
|
mypy_primer analysisAdvisory AI analysis of primer run 35406802579, attempt 1 Only SymPy changed. These differences are treated as non-blocking primer noise; no other project changed. Recorded changes: 181 added / 152 removed diagnostic headers; 181 added / 61 removed detail lines. Full evidence and limitations: download |
|
Compared candidate Type checker benchmark🟢 No performance regressions detected. Regression threshold:
Pyright stats
|
Why this change
Restore the bounded local overload-conformance case motivating #11601 without repeating the loss of type information and error checking reported in #11731. This is a new implementation following the #11739 rollback, not a reapplication of the original widening behavior.
The overload specification requires a permissive result when gradual arguments leave different return types ambiguous. For example, a
list[Any]argument can match overloads returninglist[int]andlist[str]. Choosing only the first return incorrectly rejects the validlist[str]assignment and string append.Making that result
AnyorUnknownis permitted by the specification, but it discards information we still know: both alternatives are lists, their element types are known, and neither has arbitrary members. Earlier attempts exposed the danger of gaining permissiveness by losing this information: real errors could disappear along with the unwanted conformance errors. An ordinary union is not a substitute either; its operations must be valid across the alternatives, which does not provide the required permissiveness for invariant containers.The goal is therefore to preserve as much information as possible while allowing the operations justified by the surviving overloads, rather than treating fewer diagnostics as success by itself.
How information and error checking are preserved
The internal
OverloadResultretains complete ordinary return alternatives, their generic arguments, the ordinary baseline type and the uncertainty kind. It lives inTypeResult.type, so extracting aTypedoes not silently discard the alternatives. Supported aliases and generic projections carry the alternatives forward; public queries displayOverloadResult[list[int], list[str]]honestly rather than presenting a misleading first match or erased container. This is an internal representation, not Python annotation syntax.Each supported operation requires one complete successful alternative for the entire operation. Partial successes cannot be combined across alternatives. With the example above, both invariant assignments and either int/string append are accepted, but
append(3.14), assignment tolist[bytes], a nonexistent member, or a mixed-elementextendaccepted by neither complete alternative remain errors. Different uses may select different witnesses; this is not a claim about runtime mutation correlation.Preserving a candidate's
Typealone is insufficient. Evaluation also carries incomplete/error/contextual/binding and overload metadata, cached results and diagnostics. Candidate checking uses ordinary evaluator validation with isolated cache and diagnostic ownership. A discarded trial must not leak false errors, and diagnostics for ordinary work whose caches survive must not disappear with that trial. The cold-query, query-order, speculative evaluation, cancellation and edit/restore coverage addresses these failure modes. A plausible return type by itself is not proof that an operation succeeded.Concrete calls retain ordinary precision. Unsupported producers, constructors/bound-method producers, escaping uses and unsupported gradual shapes retain ordinary behavior. Admission/proof/work limits remain bounded; exhausting them is not permission to fall back to a more permissive dynamic type. This does not claim full general overload conformance.
Automatic activation is the normal ConfigOptions/Program default, including CLI, language-server and background analysis. There is no new public setting;
experimentalOverloadResults = falseremains an internal baseline control, with explicit internal controller precedence. The separate checker live-cache handoff experiment is not adopted: production usescheckerHandoff: false, and handoff requires explicit internal opt-in.The cumulative change is substantial: 37 files, +6,459/-72 lines, including 20 production files and 15 test/sample files. It includes the original checkpoint, subsequent reviewed activation/cache/diagnostic correctness work, public type printing/transport, default wiring and documentation, not merely the latest default switch.
Validation
--threads 2CLI checks show the exact carrier and successful conformance assignments/appends. Four invalid-operation controls remain errors, including a mixed-element operation with no complete witness; the concrete control remainslist[int]with its intentional argument error. Module/function complexity behavior matches main at limits 768/4096.a07bbdearollback, pinned current main, and integrated feature, with identical frozen project files, dependencies, interpreters, options and current-main stubs. Frozen pandas source/wheel retain zero errors and complete matching 935/931 native diagnostics across all arms and historical controls. These are frozen inputs, not latest pandas catalog checkouts.message_factoryerrors in packaging and pip's vendored packaging. Both also reproduce using rollback code with current stubs; neither is introduced by this feature. Thirty native replacements change only related stub-location metadata. No historical primary error disappears; complete before/after records are retained.Performance and limits
This deliberately trades additional checking work for retained information. Collapsing an ambiguous result to a dynamic type is cheap, but prevents subsequent checks from using the original alternatives. Here, candidate operations can repeat argument matching, member lookup and code-flow evaluation, with cache isolation and diagnostic handling. The observed active-case cost is not merely the allocation cost of storing several types; that allocation cost was not independently quantified.
To limit ordinary-path cost, activation starts from a native overload match and performs bounded eligibility/proof work before building the local admission graph. Measured natural zero-use controls avoid module scans, owned candidate trials and private restoration. This is not a zero-cost claim: controller setup and request/retirement boundaries remain. Active work is bounded, and unsupported or budget-limited cases retain ordinary behavior rather than skipping required checks.
Historical pre-integration paired measurements against the same implementation with the feature explicitly off:
The large active-query percentages have small ordinary baselines, but the absolute added batch costs are real. These are whole matched workload batches, not individual queries, hover latency or IDE-wide estimates. Ordinary initial-analysis estimates were noisy, and an additional dataclass query-batch cost versus the preceding V3 implementation was inconclusive on confirmation. No claim of exact-zero overhead or an ecosystem-wide average is supported.
These costs were accepted provisionally for continuing default-on development because retaining useful error checking is the purpose of the change. Observation counters and timing runs were separate. No fresh integrated-tree timing was performed: these numbers are historical measurements, not measurements or performance certification of the updated-main implementation. External projects in the compatibility run did not activate alternatives and therefore do not establish real-world active-case performance.
Integration status
The complete feature is integrated onto pinned canonical main
916d7dc6in a fresh worktree. The original reviewed worktree and historical artifacts are preserved.Three additive conflict resolutions retain both upstream and feature additions in Program options, evaluator options/closure and cache-test imports. Upstream complexity configuration/API, contextual TypeForm lookup/tests, TypedDict union handling and updated typeshed are retained. The cumulative current-main-relative feature footprint remains 37 files, +6,459/-72. No domain, limit, default or handoff-policy change was made during integration. Publication targets only
microsoft/pyright:main.