Skip to content

[functools] Make partial covariant in its return type - #16769

Open
sumit-2007-git wants to merge 1 commit into
python:mainfrom
sumit-2007-git:fix/functools-partial-covariance
Open

sumit-2007-git wants to merge 1 commit into
python:mainfrom
sumit-2007-git:fix/functools-partial-covariance

Conversation

@sumit-2007-git

Copy link
Copy Markdown

Partially addresses #10566 (specifically functools.partial; partialmethod and singledispatch are left untouched to avoid overlapping with #16736 and #15635).

functools.partial only exposes _T via read-only properties (func) and return positions (__call__, __get__) plus __new__, so _T_co makes partial[Child] assignable to partial[Parent], as noted by @JelleZijlstra in #10566.

Verification

  • Added a covariance test (check_partial_covariance) in stdlib/@tests/test_cases/check_functools.py.
  • Tested locally with mypy (3.10, 3.14), pyright (stricter 3.10, 3.14, and testcases 3.12), ty, pyrefly, stubtest on functools, regr_test, ruff, black, flake8, and check_typeshed_structure.py.

@github-actions

Copy link
Copy Markdown
Contributor

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

jax (https://github.com/google/jax)
- jax/experimental/pallas/ops/tpu/splash_attention/splash_attention_kernel.py:2598: error: Argument 1 to "_process_dynamic_mask" has incompatible type "Array | MultiHeadMask"; expected "Array"  [arg-type]
- jax/experimental/pallas/ops/tpu/splash_attention/splash_attention_kernel.py:2614: error: Argument 1 to "_process_dynamic_mask" has incompatible type "Array | MultiHeadMask"; expected "Array"  [arg-type]
- jax/experimental/pallas/ops/tpu/splash_attention/splash_attention_kernel.py:2615: error: Argument 2 to "_process_dynamic_mask" has incompatible type "tuple[int | Any | None, int | Any | None]"; expected "tuple[int, int]"  [arg-type]
- jax/experimental/pallas/ops/tpu/splash_attention/splash_attention_kernel.py:2624: error: Argument 1 to "_process_dynamic_mask" has incompatible type "Array | MultiHeadMask"; expected "Array"  [arg-type]
- jax/experimental/pallas/ops/tpu/splash_attention/splash_attention_kernel.py:2625: error: Argument 2 to "_process_dynamic_mask" has incompatible type "tuple[int | Any | None, int | Any | None]"; expected "tuple[int, int]"  [arg-type]

This branch has not been deployed

No deployments
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.

1 participant