Skip to content

Conversation

@johnslavik
Copy link
Member

@johnslavik johnslavik commented Jan 6, 2026

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.

@johnslavik

This comment was marked as resolved.

@johnslavik johnslavik marked this pull request as draft January 19, 2026 23:59
@johnslavik

This comment was marked as resolved.

@johnslavik johnslavik added DO-NOT-MERGE and removed needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 20, 2026
@johnslavik
Copy link
Member Author

johnslavik commented Jan 20, 2026

Hm, sorry, I think I was wrong. I've forgotten that a workaround for any potential (still unlikely) breakage is dead simple -- just .register(the_class) instead. That's what the exception message says. Most of my backward compatibility worries were not significant; please forget them. A breakage could only be problematic with third-party libraries, but I believe it to be extremely improbable that their type annotation-based singledispatch registrations would be incorrect. This is rather poor application programming smell.

@johnslavik johnslavik added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 20, 2026
@johnslavik johnslavik marked this pull request as ready for review January 20, 2026 03:00
@johnslavik
Copy link
Member Author

@pR0Ps, I took your test from GH-143888 and committed it with you as an author.

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

Labels

awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants