Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zuo opened this issue Jun 12, 2024 · 2 comments
Closed

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

zuo opened this issue Jun 12, 2024 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@zuo
Copy link
Contributor

zuo commented Jun 12, 2024

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

@zuo zuo added the type-bug An unexpected behavior, bug, or error label Jun 12, 2024
zuo added a commit to zuo/cpython that referenced this issue Jun 12, 2024
The inspect.ismethoddescriptor() function did not check for the lack of
__delete__() and, consequently, erroneously returned True when applied
to *data* descriptors with __get__() and __delete__().
ncoghlan added a commit that referenced this issue Jun 18, 2024
The `inspect.ismethoddescriptor()` function did not check for the lack of
`__delete__()` and, consequently, erroneously returned True when applied
to *data* descriptors with only `__get__()` and `__delete__()` defined.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 18, 2024
The `inspect.ismethoddescriptor()` function did not check for the lack of
`__delete__()` and, consequently, erroneously returned True when applied
to *data* descriptors with only `__get__()` and `__delete__()` defined.

(cherry picked from commit dacc5ac)

Co-authored-by: Jan Kaliszewski <zuo@kaliszewski.net>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
ncoghlan added a commit that referenced this issue Jun 19, 2024
The `inspect.ismethoddescriptor()` function did not check for the lack of
`__delete__()` and, consequently, erroneously returned True when applied
to *data* descriptors with only `__get__()` and `__delete__()` defined.

(cherry picked from commit dacc5ac)

Co-authored-by: Jan Kaliszewski <zuo@kaliszewski.net>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
@ncoghlan
Copy link
Contributor

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

picnixz added a commit to picnixz/cpython that referenced this issue Jun 19, 2024
The `inspect.ismethoddescriptor()` function did not check for the lack of
`__delete__()` and, consequently, erroneously returned True when applied
to *data* descriptors with only `__get__()` and `__delete__()` defined.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
@zuo
Copy link
Contributor Author

zuo commented Jun 19, 2024

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

Thank you too! :)

mrahtz pushed a commit to mrahtz/cpython that referenced this issue Jun 30, 2024
The `inspect.ismethoddescriptor()` function did not check for the lack of
`__delete__()` and, consequently, erroneously returned True when applied
to *data* descriptors with only `__get__()` and `__delete__()` defined.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
The `inspect.ismethoddescriptor()` function did not check for the lack of
`__delete__()` and, consequently, erroneously returned True when applied
to *data* descriptors with only `__get__()` and `__delete__()` defined.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
The `inspect.ismethoddescriptor()` function did not check for the lack of
`__delete__()` and, consequently, erroneously returned True when applied
to *data* descriptors with only `__get__()` and `__delete__()` defined.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants