Skip to content

Add functools.partial.__get__ for Python 3.14#15977

Open
apoorvdarshan wants to merge 3 commits into
python:mainfrom
apoorvdarshan:partial-descriptor-314
Open

Add functools.partial.__get__ for Python 3.14#15977
apoorvdarshan wants to merge 3 commits into
python:mainfrom
apoorvdarshan:partial-descriptor-314

Conversation

@apoorvdarshan

Copy link
Copy Markdown
Contributor

Fixes #15974.

Python 3.14 made functools.partial a descriptor (python/cpython#121027), adding a __get__ method, but the stub was missing it.

This adds __get__ to partial, gated on sys.version_info >= (3, 14), mirroring the existing partialmethod.__get__ in the same file (-> Callable[..., _T]).

The runtime signature on 3.14 is (self, instance, owner=None, /) (positional-only), which the stub matches. When accessed on an instance the descriptor returns a bound method; on the class it returns the partial itself — both are Callable[..., _T].

python tests/stubtest_stdlib.py functools passes on 3.14 with this change (no new stubtest errors), and tests/mypy_test.py stdlib/functools.pyi succeeds.


Disclosure: this change was prepared with the assistance of an AI tool (Claude Code). I verified the behavior against CPython 3.14, ran stubtest and the mypy test locally, and take responsibility for the contribution and will respond to review feedback personally.

@github-actions

This comment has been minimized.

@srittau

srittau commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

There are failing CI checks. Please have a look at them before we can consider this PR.

@apoorvdarshan

Copy link
Copy Markdown
Contributor Author

Thanks @srittau. Fixed the CI failure: the new functools.partial.__get__ base signature (optional owner, returns Callable[..., _T]) made boltons' InstancePartial/CachedInstancePartial __get__ overrides [override]-incompatible, since they declared obj_type as required and untyped. I updated both overrides to match the base (positional-only params, optional obj_type: type[Any] | None = None, return Callable[..., Incomplete]). mypy_test.py stubs/boltons now passes on both 3.14 and 3.15, and the stdlib change is unchanged.

@github-actions

This comment has been minimized.

@apoorvdarshan

Copy link
Copy Markdown
Contributor Author

@srittau The previous commit resolved the mypy [override] error but broke stubtest: boltons's runtime __get__(self, obj, obj_type) requires obj_type (no default, positional-or-keyword), which no longer matched the stub after I added a default and /.

I've reverted both InstancePartial.__get__ and CachedInstancePartial.__get__ back to a signature matching the runtime (def __get__(self, obj, obj_type): ...) and added # type: ignore[override] for the LSP incompatibility that the new functools.partial.__get__ base method introduces (the base's owner is optional, but boltons requires obj_type). Also dropped the now-unused Any/Callable imports.

Verified locally: mypy_test.py stubs/boltons passes on both 3.14 and 3.15, and stubtest_third_party.py boltons now reports success.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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.

functools.partial should be a descriptor in 3.14

2 participants