Skip to content

inspect.ismethoddescriptor(): lack of __delete__() is not checked #120381

Description

@zuo

Bug report

Bug description:

The inspect.ismethoddescriptor() function reports descriptor objects which implement __delete__() but not __set__() as method descriptors, even though they are, in fact, data descriptors:

Actual behavior example:

>>> import inspect
>>> class Descriptor:
...     def __get__(self, *_): pass
...     def __delete__(self, *_): pass  # Note: `__set__()` *not* defined.
...
>>> inspect.ismethoddescriptor(Descriptor())  # Wrong result:
True

Expected result:

>>> inspect.ismethoddescriptor(Descriptor())  # Correct result:
False

See also: https://discuss.python.org/t/inspect-ismethoddescriptor-checks-for-the-lack-of-set-but-ignores-delete-should-it-be-fixed/55039


There is an additional question: to which Python versions should the fix be applied?

IMHO, the fix can be safely applied to the branches 3.14 (main) and 3.13 (still in the beta phase). Backporting it to the earlier versions might be considered too disruptive. Obviously, the decision will need to be made by a core developer, not me.


CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12, 3.13, CPython main branch

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Jun 12, 2024
  2. added a commit that references this issue on Jun 12, 2024
  3. added a commit that references this issue on Jun 18, 2024
  4. added a commit that references this issue on Jun 18, 2024
  5. added a commit that references this issue on Jun 19, 2024
  6. ncoghlan commented on Jun 19, 2024

    @ncoghlan
    Contributor

    Merged and fixed for the next 3.13 beta. Thanks for the report and PR, @zuo!

  7. added a commit that references this issue on Jun 19, 2024
  8. zuo commented on Jun 19, 2024

    @zuo
    ContributorAuthor

    Merged and fixed for the next 3.13 beta. Thanks for the report and PR, @zuo!

    Thank you too! :)

  9. added a commit that references this issue on Jun 30, 2024
  10. added a commit that references this issue on Jul 11, 2024
  11. added a commit that references this issue on Jul 17, 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

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions