Skip to content

gh-84644: Fix singledispatch annotation parsing - #143465

Open
johnslavik wants to merge 108 commits into
python:mainfrom
johnslavik:fix-singledispatch-annotation-parsing
Open

johnslavik wants to merge 108 commits into
python:mainfrom
johnslavik:fix-singledispatch-annotation-parsing

Conversation

@johnslavik

@johnslavik johnslavik commented Jan 6, 2026 •

Copy link
Copy Markdown
Member

A very practical but more general approach than GH-140255 to fixing annotation parsing in functools.singledispatch and functools.singledispatchmethod.

Fixes issues GH-84644, GH-130827, and GH-143886.

It can be broken if one uses a user-defined alternative implementation of staticmethod or something analogous.
Will break incorrect but working registrees. I haven't investigated stripping Annotated typeforms yet.

Consulting a test which fails with this fix at https://github.com/python/cpython/pull/130309/changes#r2663516538 -- I think that the test is wrong.

Comment thread Lib/functools.py Outdated
@johnslavik

This comment was marked as resolved.

Comment thread Lib/functools.py Outdated
Comment thread Lib/functools.py Outdated
@johnslavik johnslavik added the needs backport to 3.15 bugs and security fixes label Jul 20, 2026
@johnslavik
johnslavik force-pushed the fix-singledispatch-annotation-parsing branch from 0d72cec to a5a79ad Compare July 20, 2026 23:41
@johnslavik

johnslavik commented Jul 20, 2026 •

Copy link
Copy Markdown
Member Author

@picnixz, could you please re-review? :)

(The force-push was intentional; I know this is discouraged but I want to save noise, you can still follow what happened.)

Comment thread Lib/functools.py Outdated
@read-the-docs-community

read-the-docs-community Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

@johnslavik
johnslavik requested a review from picnixz July 21, 2026 02:13
Comment thread Doc/deprecations/pending-removal-in-3.18.rst Outdated
Comment thread Doc/library/functools.rst

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure it's valuable to specifically disallow return annotations if we still allow dispatching by annotations on wrong parameters.

@johnslavik

johnslavik commented Aug 30, 2026 •

Copy link
Copy Markdown
Member Author

I'm not sure it's valuable to specifically disallow return annotations if we still allow dispatching by annotations on wrong parameters.

We could deprecate cases when the chosen parameter isn't the same as in my new formula. @picnixz prefers to just document the limitation. And when the deprecation ends, we break custom descriptors that emulate static method behavior (which nowadays seems less of a risk than I originally thought, case looks extremely rare and it's a trivial fix).

@encukou

encukou commented Sep 2, 2026

Copy link
Copy Markdown
Member

I'm not sure it's valuable to specifically disallow return annotations if we still allow dispatching by annotations on wrong parameters.

Yeah, it's not very valuable. But in other cases we can't really be sure something is wrong, and the check is cheap. +0; I'd merge it.

@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 20, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Sprint Oct 20, 2026
@johnslavik johnslavik removed the needs backport to 3.13 only security fixes label Oct 20, 2026
@encukou encukou removed needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 20, 2026
@encukou

encukou commented Oct 20, 2026

Copy link
Copy Markdown
Member

New deprecations should not get backported. The docs improvements will need manual backports.

encukou
encukou previously approved these changes Oct 20, 2026
@encukou
encukou dismissed their stale review October 20, 2026 17:11

I was too quick :/

Comment thread Doc/library/functools.rst Outdated
@rhettinger
rhettinger removed their request for review October 20, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants