Repository navigation
Allow non-descriptor callables in functools.singledispatchmethod #140873
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Nov 1, 2025 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Nov 1, 2025 This never worked, so it can be considered a new feature.
The docstring should be corrected in 3.14 and older.
- addedtype-featureA feature request or enhancementA feature request or enhancementand removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Nov 2, 2025 - changed the title
[-]`functools.singledispatchmethod` crashes with `AttributeError` for registered non-descriptor callables, violating documentation guarantee[/-][+]Allow non-descriptor callables in `functools.singledispatchmethod`[/+]on Nov 2, 2025 I'll categorize this as a new feature as this is the main point of this issue (and considering no one complained until now I think we can safely assume that it wasn't assumed so).
But we need to correct the docstring otherwise (as part of this issue). Adding support for non-descriptors would possibly break existing code so better to consider this a new feature.
Although we have several tests for non-descriptor callable (I think they were added by me). They are passed because the methods were not called, we only tested other their properties.
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Bug report
Bug description:
When a non-descriptor callable (such as a lambda or a class instance) is registered as a handler,
singledispatchmethodunconditionally attempts to call the__get__method on that handler during dispatch.This results in an AttributeError, because non-descriptor callables do not have a get method.
This behavior directly violates the explicit guarantee in
singledispatchmethod's own docstring, which states that it does handle non-descriptor callables.CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs