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 — 3.13.0b3: undocumented change in `inspect.isroutine()` for `functools.partial` · Issue #122087 · python/cpython

3.13.0b3: undocumented change in inspect.isroutine() for functools.partial #122087

New issue
Copy link
New issue
Copy link
Closed
Closed
3.13.0b3: undocumented change in inspect.isroutine() for functools.partial#122087
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirrelease-blocker

Description

@mgorny
mgorny
opened on Jul 21, 2024
Issue body actions

Documentation

While investigating Kludex/starlette#2648, I've noticed that the behavior of inspect.isroutine() changed with regards to functools.partial().

Please consider the following sample:

import inspect
from functools import partial

def foo(x):
    pass

p = partial(foo, 1)
print(inspect.isroutine(p))

Prior to 3.13.0b3, it would evaluate to False. In newer versions, it evaluates to True.

A bisect points out that it changed as a result of 49e5740 (i.e. #121086). Neither the commit message, nor the news entry, hints anything about inspect.isroutine() behavior.

Could you please clarify whether the change was intentional? And if it was, could we have it explicitly noted in the documentation?

Linked PRs

  • [3.13] gh-122087: Restore ismethoddescriptor() and isroutine() for partial objects #122218
  • gh-122087: Add tests for ismethoddescriptor() and isroutine() with partial objects #122219

Activity

  1. mgorny
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Jul 21, 2024
  2. mgorny commented on Jul 21, 2024

    @mgorny
    mgorny
    on Jul 21, 2024
    ContributorAuthor
    More actions

    CC @serhiy-storchaka

  3. hugovk
    added
    release-blocker
    on Jul 21, 2024
  4. ezio-melotti
    added this to Release and Deferred blockers 🚫on Jul 21, 2024
  5. github-project-automation
    moved this to Todo in Release and Deferred blockers 🚫on Jul 21, 2024
  6. hugovk commented on Jul 21, 2024

    @hugovk
    hugovk
    on Jul 21, 2024
    Member
    More actions

    I added the release-blocker label to make sure this is addressed one way or another before RC1 on the 30th.

    Reacted by Marcelo Trylesinski
  7. ncoghlan commented on Jul 22, 2024

    @ncoghlan
    ncoghlan
    on Jul 22, 2024
    Contributor
    More actions

    Reviewing the issue, I suspect functools.partial may need further special-casing in inspect for 3.13 (the addition of the descriptor method doesn't currently change its behaviour, but some of the inspect functions are already treating it as if the 3.14 change was already in effect)

    In the backport PR, https://github.com/python/cpython/pull/121092/files#diff-b89cd06e4637abacb73f2500301ff979a67ad7ecbfa7cf151c7243715898d7eaL2558 adjusted _signature_from_callable to avoid having the addition of __get__ change the reported signature, which was enough to keep CI happy, but it appears that doesn't cover the whole of the inspect module when it comes to partial object handling.

  8. encukou commented on Jul 23, 2024

    @encukou
    encukou
    on Jul 23, 2024
    Member
    More actions

    @serhiy-storchaka, will you be able to look at this before rc1?

  9. serhiy-storchaka commented on Jul 24, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jul 24, 2024
    Member
    More actions

    Unfortunately, the only way to add a warning about a partial object being made a method descriptor in the future is to make it a method descriptor. We can make inspect.ismethoddescriptor() lying about partial objects, but this will not help the user code which check the __get__ method directly. I do not know how to break this loop.

  10. mgorny commented on Jul 24, 2024

    @mgorny
    mgorny
    on Jul 24, 2024
    ContributorAuthor
    More actions

    What's the expected result in 3.14? Is partial() there expected to be recognized as a routine, and not have a __name__ attribute? Ideally, is there some documentation that explains whether __name__ is expected on all routines or not?

  11. serhiy-storchaka
    added 2 commits that reference this issue on Jul 24, 2024

    pythongh-122087: Restore ismethoddescriptor() and isroutine() for par…

    df88fc6

    pythongh-122087: Add tests for ismethoddescriptor() and isroutine() w…

    f10bf09
  12. serhiy-storchaka commented on Jul 24, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jul 24, 2024
    Member
    More actions

    Yes, not all method descriptors (and therefore not all routines) have the __name__ attribute. This always was so, you always should have a fallback.

    #122218 add a special case for partial in ismethoddescriptor() and tests for 3.13. #122219 adds corresponding tests for main branch.

  13. serhiy-storchaka
    added 2 commits that reference this issue on Jul 25, 2024

    [3.13] gh-122087: Restore ismethoddescriptor() and isroutine() for pa…

    4e77165

    gh-122087: Add tests for ismethoddescriptor() and isroutine() with pa…

    bb10858
  14. serhiy-storchaka
    closed this as completedon Jul 25, 2024
  15. github-project-automation
    moved this from Todo to Done in Release and Deferred blockers 🚫on Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dirrelease-blocker

    Projects

    • Release and Deferred blockers 🚫
      Status
      Done
      Show more project fields

    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.