Skip to content

Fix #11470: Pyright is incorrectly handling overload functions - #11498

Merged
Rich Chiodo (rchiodo) merged 1 commit into
microsoft:mainfrom
rchiodo:fix11470
Jun 29, 2026
Merged

Rich Chiodo (rchiodo) merged 1 commit into
microsoft:mainfrom
rchiodo:fix11470

Conversation

@rchiodo

Copy link
Copy Markdown
Collaborator

Description

Fixes a false positive where Pyright reported reportUnknownParameterType and reportMissingParameterType on the implementation of an overloaded function. Per the typing spec, only the @overload signatures define the function's public type; the implementation signature is ignored by the type checker, so its parameters are permitted to remain unannotated. Pyright was incorrectly flagging unannotated parameters on the implementation under strict mode.

How you figured out what to do

The unknown/missing parameter type checks in checker.ts ran unconditionally for every function definition. Overload implementations were not exempted, even though their signatures carry no type-checking weight. The fix is to detect overload implementations and skip these two specific diagnostics for them.

Implementation

In packages/pyright-internal/src/analyzer/checker.ts, compute whether the current function is an overload implementation:

const isOverloadImplementation =
    isOverloaded(functionTypeResult.decoratedType) &&
    !FunctionType.isOverloaded(functionTypeResult.functionType);

The decorated type is overloaded (the symbol has @overload signatures), but the function type itself is not marked overloaded — which uniquely identifies the implementation function. This guard is then added to the reportUnknownParameterType and reportMissingParameterType checks so they are skipped for the implementation only. All other functions (including non-overloaded ones and the @overload signatures themselves) continue to be checked as before.

Testing

Added packages/pyright-internal/src/tests/samples/overloadImpl3.py under # pyright: strict, covering:

  • An overloaded method (Foo.foo) with an unannotated value parameter on the implementation — should produce no errors.
  • An overloaded free function (func1) with an unannotated implementation parameter — should produce no errors.
  • A regular non-overloaded function (func2) with an unannotated parameter — should still produce both the unknown-type and missing-annotation errors (2 expected errors).

Wired up OverloadImpl3 in typeEvaluator6.test.ts, asserting exactly 2 errors so the regression coverage confirms both that the implementation is exempt and that ordinary functions are unaffected.

Run with:

cd packages/pyright/packages/pyright-internal
node node_modules\jest\bin\jest typeEvaluator6 --runInBand --detectOpenHandles --forceExit --testTimeout=180000 -t "OverloadImpl3"

Addresses

Fixes https://github.com/microsoft/pylance-release/issues/11470


Generated by fix_all_my_issues pipeline

An overload implementation's signature is ignored by the type checker (only the @overload signatures define the function's type), so per the typing spec its parameters are allowed to remain unannotated. Skip reportUnknownParameterType and reportMissingParameterType for the implementation function's parameters.

Fixes microsoft#11470

Co-authored-by: Copilot <[email protected]>
@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/stats/frv_types.py:139:17 - error: Argument of type "NaN | ComplexInfinity | Rational | Unknown | Expr" cannot be assigned to parameter "value" of type "int" in function "__setitem__"
+     Type "NaN | ComplexInfinity | Rational | Unknown | Expr" is not assignable to type "int"
+       "Expr" is not assignable to "int" (reportArgumentType)
-   .../projects/sympy/sympy/stats/rv.py:473:25 - error: Argument of type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum | ZeroMatrix | NaN | Piecewise | Basic | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
-     Type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum | ZeroMatrix | NaN | Piecewise | Basic | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" is not assignable to type "Expr | complex"
+   .../projects/sympy/sympy/stats/rv.py:473:25 - error: Argument of type "Expr | Lambda | Zero | One | Integral | Unknown | NegativeOne | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Probability | tuple[Unknown, ...] | Sum | ZeroMatrix | Add | Piecewise | Basic | int" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
+     Type "Expr | Lambda | Zero | One | Integral | Unknown | NegativeOne | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Probability | tuple[Unknown, ...] | Sum | ZeroMatrix | Add | Piecewise | Basic | int" is not assignable to type "Expr | complex"
-   .../projects/sympy/sympy/stats/stochastic_process_types.py:1839:25 - error: Argument of type "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Zero | NaN | Piecewise | Basic | Integral | Any | int" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
+   .../projects/sympy/sympy/stats/stochastic_process_types.py:1839:25 - error: Argument of type "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Add | Zero | NaN | Piecewise | Basic | Integral | Any | int" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
-     Type "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Zero | NaN | Piecewise | Basic | Integral | Any | int" is not assignable to type "Expr | complex"
+     Type "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Add | Zero | NaN | Piecewise | Basic | Integral | Any | int" is not assignable to type "Expr | complex"
-     Return type mismatch: base method returns type "Self@Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | Self@Expectation | Literal[0]"
+     Return type mismatch: base method returns type "Self@Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | Self@Expectation | Literal[0]"
-       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | Expectation* | Literal[0]" is not assignable to type "Basic"
+       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | Expectation* | Literal[0]" is not assignable to type "Basic"
+   .../projects/sympy/sympy/stats/symbolic_probability.py:75:9 - error: Method "doit" overrides class "Basic" in an incompatible manner
+     Return type mismatch: base method returns type "Basic", override returns type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | Add | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]"
+       Type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | Add | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" is not assignable to type "Basic"
+         "Literal[0]" is not assignable to "Basic" (reportIncompatibleMethodOverride)
-     Return type mismatch: base method returns type "Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | Literal[0]"
+     Return type mismatch: base method returns type "Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | Literal[0]"
-       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | Literal[0]" is not assignable to type "Basic"
+       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | Literal[0]" is not assignable to type "Basic"
+   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:97:29 - error: Cannot access attribute "symbol" for class "ConditionalFiniteDomain"
+     Attribute "symbol" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:367:12 - error: Operator "-" not supported for types "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" and "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]"
+   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:367:12 - error: Operator "-" not supported for types "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" and "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]"
-   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:415:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
+   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:415:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
-     Type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" is not assignable to type "Basic"
+     Type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" is not assignable to type "Basic"
-   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1005:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
+   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1005:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
-     Type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" is not assignable to type "Basic"
+     Type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" is not assignable to type "Basic"
-   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1060:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
+   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1060:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
-     Type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" is not assignable to type "Basic"
+     Type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | ZeroMatrix | Add | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0]" is not assignable to type "Basic"

... (truncated 612 lines) ...

// signatures define the function's type). Per the typing spec, the
// implementation's parameters are allowed to remain unannotated, so
// skip the unknown/missing parameter type checks for it.
const isOverloadImplementation =

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This uses a non-canonical detection idiom. The same file already exposes the explicit, intended API for exactly this question: OverloadedType.getImplementation(functionTypeResult.decoratedType) === functionTypeResult.functionType (used at checker.ts:718-719, and several times in typeUtils.ts). This change instead copies the looser heuristic from skipUnsolvableTypeVarCheck (checker.ts:2531-2533), creating a third inline copy of overload-implementation detection. Prefer extracting a single private helper (e.g. isOverloadImplementation(funcTypeResult)) built on getImplementation(...) and reuse it both here and at the existing heuristic site. Functionally equivalent today, but self-documenting and single-source-of-truth.

// implementation's parameters are allowed to remain unannotated, so
// skip the unknown/missing parameter type checks for it.
const isOverloadImplementation =
isOverloaded(functionTypeResult.decoratedType) &&

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Please confirm the premise before merging. The justification "the implementation signature is ignored by the type checker" applies to call-site typing, but the implementation body is still type-checked and the param still resolves to Unknown. Pyright's documented reportMissingParameterType exemptions are only self/cls, with no mention of overload implementations, so this may be intentional strict-mode behavior rather than a false positive. Since this is an upstream pyright change to documented strict-mode semantics, verify with the Pyright maintainer that this is genuinely considered a false positive to avoid a likely rejection / local divergence.

@rchiodo

Copy link
Copy Markdown
Collaborator Author

Targeted fix with a focused regression test. Two notes worth addressing before merge: (1) prefer the canonical OverloadedType.getImplementation(...) API instead of adding a third inline overload-implementation heuristic, and (2) confirm with upstream that strict-mode reporting on overload implementations is genuinely considered a false positive rather than intended behavior.

@heejaechang

Copy link
Copy Markdown
Collaborator

Fix looks correct for the reported overload-implementation false positives. Two follow-ups worth considering before merge: (1) the same 'implementation signature is ignored' rationale arguably applies to the impl's return type, which is not exempted here, and (2) per the repo's Pyright↔Pylance split, the primary regression test should live in the Pylance harness with the pyright-internal test as additional coverage.

@heejaechang

Copy link
Copy Markdown
Collaborator

Fix looks correct and the predicate uniquely selects the overload implementation. Two non-blocking notes: (1) per the Pyright↔Pylance split policy, a pylance-release fix should have its primary regression test in the Pylance harness; (2) the same 'implementation signature is ignored' rationale arguably applies to the implementation's return type, so it's worth either extending the exemption or documenting that this is params-only.

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 da05559 into microsoft:main Jun 29, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants