Skip to content

Fix overload selection with nested Any and object fallback - #4533

Open
ting-hong-shieh wants to merge 2 commits into
facebook:mainfrom
ting-hong-shieh:agent/fix-nested-any-object-fallback
Open

Fix overload selection with nested Any and object fallback#4533
ting-hong-shieh wants to merge 2 commits into
facebook:mainfrom
ting-hong-shieh:agent/fix-nested-any-object-fallback

Conversation

@ting-hong-shieh

Copy link
Copy Markdown

Summary

  • prefer a specific overload over a later object fallback when nested gradual types create ambiguity in compatibility mode
  • keep top-level Any ambiguous and preserve spec-compliant overload behavior
  • add regression coverage for the original equality case and both guard cases

Root cause

Overload evaluation materialized the nested Any in the argument during step 5. The materialized argument could no longer select the bounded generic overload, so the later object fallback remained in the candidate set. Because the two overloads had incompatible return types, the call resolved to Unknown.

Validation

  • cargo test test::overload (117 passed)
  • python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema
  • git diff --check

Fixes #3977

Prefer a specific overload over later object fallbacks when only nested gradual types create ambiguity in compatibility mode. Keep top-level Any ambiguous and leave spec-compliant overload evaluation unchanged.
@meta-cla meta-cla Bot added the cla signed label Aug 13, 2026
@ting-hong-shieh
ting-hong-shieh marked this pull request as ready for review August 13, 2026 08:35
@meta-codesync

meta-codesync Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D115850637. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

This comment has been minimized.

@rchen152 rchen152 self-assigned this Aug 13, 2026
@github-actions
github-actions Bot requested a review from stroxler August 13, 2026 09:30
@github-actions github-actions Bot added size/m and removed size/m labels Aug 13, 2026
@github-actions

Copy link
Copy Markdown

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

============================================================
SUMMARY
============================================================
Total: +11 new errors, -24 fixed errors

Projects with changes (3):
  scipy: +1 -1
  scikit-learn: +0 -3
  pandas: +10 -20
============================================================

FULL DIFF DETAILS
------------------------------------------------------------

scipy (https://github.com/scipy/scipy)
- ERROR scipy/signal/_spectral_py.py:231:13-57: Implicit conversion of `numpy.bool | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR scipy/signal/_spectral_py.py:231:13-57: Implicit conversion of `numpy.bool` to `bool` is not allowed [implicit-bool]

scikit-learn (https://github.com/scikit-learn/scikit-learn)
- ERROR sklearn/decomposition/_nmf.py:395:19-57: The type of `permutation` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR sklearn/feature_extraction/text.py:1310:21-63: The type of `j_indices` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR sklearn/neighbors/_classification.py:306:20-59: The type of `mode` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]

pandas (https://github.com/pandas-dev/pandas)
- ERROR pandas/core/arrays/sparse/array.py:2151:8-24: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:492:16-30: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:509:20-34: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:574:16-30: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:589:16-30: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:589:16-73: Implicit conversion of `Literal[False] | NDFrame | numpy.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/arrays/string_.py:589:16-73: Implicit conversion of `Literal[False] | numpy.bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:887:20-28: Object of class `bool` has no attribute `any` [missing-attribute]
+ ERROR pandas/core/arrays/string_.py:887:20-30: Implicit conversion of `numpy.bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/dtypes/cast.py:1422:8-53: Implicit conversion of `Literal[0] | NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/dtypes/cast.py:1422:8-53: Implicit conversion of `Literal[0] | bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/dtypes/cast.py:1429:16-27: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/indexes/multi.py:4243:28-36: Implicit conversion of `signedinteger[_NBitIntP] | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/indexes/multi.py:4243:28-36: Implicit conversion of `signedinteger[_NBitIntP]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/indexes/multi.py:4253:28-36: Implicit conversion of `signedinteger[_NBitIntP] | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/indexes/multi.py:4253:28-36: Implicit conversion of `signedinteger[_NBitIntP]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/indexing.py:3893:16-29: Implicit conversion of `Literal[False] | numpy.bool | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/indexing.py:3893:16-29: Implicit conversion of `Literal[False] | numpy.bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/internals/construction.py:413:16-48: Implicit conversion of `Literal[False] | ndarray[tuple[Any, ...], dtype[numpy.bool]] | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/internals/construction.py:413:16-48: Implicit conversion of `Literal[False] | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/nanops.py:369:24-40: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/strings/accessor.py:731:16-34: Implicit conversion of `numpy.bool | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/strings/accessor.py:731:16-34: Implicit conversion of `numpy.bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/io/pytables.py:5980:8-16: Object of class `bool` has no attribute `any` [missing-attribute]
+ ERROR pandas/io/pytables.py:5980:8-18: Implicit conversion of `numpy.bool` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/io/pytables.py:5980:8-38: Implicit conversion of `builtins.bool | numpy.bool | Unknown` to `bool` is not allowed [implicit-bool]
- ERROR pandas/io/pytables.py:5986:45-49: Argument `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` is not assignable to parameter `mask` with type `ndarray` in function `_make_index_nan_rep` [bad-argument-type]
- ERROR pandas/io/pytables.py:5987:38-43: Unary `~` is not supported on `bool` [deprecated]
- ERROR pandas/plotting/_matplotlib/hist.py:102:18-39: The type of `values` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR pandas/plotting/_matplotlib/hist.py:104:39-45: The type of this argument is unknown [unknown-argument-type]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overloaded method with TypeVar(bound=tuple[int, ...]) resolves to Unknown when object fallback overload is present

3 participants