GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow non-descriptor callables in `functools.singledispatchmethod` · Issue #140873 · python/cpython

Allow non-descriptor callables in functools.singledispatchmethod #140873

New issue
Copy link
New issue
Copy link
Closed
Closed
Allow non-descriptor callables in functools.singledispatchmethod#140873
Copy link
Assignees
serhiy-storchaka
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

@T90REAL
T90REAL
opened on Nov 1, 2025
Issue body actions

Bug report

Bug description:

When a non-descriptor callable (such as a lambda or a class instance) is registered as a handler, singledispatchmethod unconditionally 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.

import functools

class MyCallable:
    def __call__(self, host_self, arg):
        return f"Handled {arg} via MyCallable"

class Host:
    @functools.singledispatchmethod
    def my_method(self, arg):
        return f"Base handling for {arg}"

callable_instance = MyCallable()
Host.my_method.register(int, callable_instance)


h = Host()

h.my_method(123)
AttributeError: 'MyCallable' object has no attribute '__get__'. Did you mean: '__ge__'?

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

  • gh-140873: Add support of non-descriptor callables in functools.singledispatchmethod() #140884
  • [3.14] gh-140873: Fix the singledispatchmethod documentation #141523
  • [3.13] gh-140873: Fix the singledispatchmethod documentation (GH-141523) #141710

Activity

  1. T90REAL
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Nov 1, 2025
  2. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Nov 1, 2025
  3. serhiy-storchaka
    self-assigned this
    on Nov 1, 2025
  4. serhiy-storchaka
    added a commit that references this issue on Nov 1, 2025

    pythongh-140873: Add support of non-descriptor callables in functools…

    ab8e8e9
  5. serhiy-storchaka commented on Nov 1, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Nov 1, 2025
    Member
    More actions

    This never worked, so it can be considered a new feature.

    The docstring should be corrected in 3.14 and older.

  6. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Nov 2, 2025
  7. picnixz
    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
  8. picnixz commented on Nov 2, 2025

    @picnixz
    picnixz
    on Nov 2, 2025
    Member
    More actions

    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.

  9. serhiy-storchaka commented on Nov 2, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Nov 2, 2025
    Member
    More actions

    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.

  10. serhiy-storchaka
    added 2 commits that reference this issue on Nov 13, 2025

    gh-140873: Add support of non-descriptor callables in functools.singl…

    b2b68d4

    pythongh-140873: Fix the singledispatchmethod documentation

    a0ff169
  11. CuriousLearner
    added 3 commits that reference this issue on Nov 13, 2025

    Merge branch 'main' into fix-issue21914

    b9f473c

    Merge branch 'main' of github.com:python/cpython into fix-Issue18387

    c46ecc5

    Merge branch 'main' of github.com:python/cpython into fix-issue24255

    c240289
  12. serhiy-storchaka
    added a commit that references this issue on Nov 18, 2025

    [3.14] gh-140873: Fix the singledispatchmethod documentation (GH-141523)

    d89eb2f
  13. miss-islington
    added a commit that references this issue on Nov 18, 2025

    [3.14] pythongh-140873: Fix the singledispatchmethod documentation (p…

    802dfd9
  14. serhiy-storchaka
    closed this as completedon Nov 18, 2025
  15. serhiy-storchaka
    added a commit that references this issue on Nov 18, 2025

    [3.13] gh-140873: Fix the singledispatchmethod documentation (GH-141523…

    8f71888
  16. StanFromIreland
    added a commit that references this issue on Dec 6, 2025

    pythongh-140873: Add support of non-descriptor callables in functools…

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

Metadata

Metadata

Assignees

  • @serhiy-storchaka
    serhiy-storchaka

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.