-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Fix data descriptor detection in inspect.getattr_static #75367
Comments
inspect.getattr_static is currently not identifying data descriptors the right way. Data descriptors are defined by having a __get__ attribute and at least one of the __set__ and __delete__ attributes. Implementation detail: Both __delete__ and __get__ set the same slot called tp_descr_set in CPython. I have attached a patch that fixes the issue IMO. |
See also bpo-26103. |
This is not a duplicate. It is related to https://bugs.python.org/issue26103, because __get__ is not required anymore for an object to be a data descriptor. The current code on master (of inspect.getattr_static) still thinks a descriptor has both __get__ and __set__ set. Since issue bpo-26103 has been fixed, it's now clear that my patch is slightly wrong, but I'm happy to fix that if someone is actually going to review it. |
Can you give an example of where getattr_static() is not doing what you expect? |
@davidhalter Please do update the patch. And please add a unit test that is currently failing so we can see what bug you are fixing. |
Thanks for bringing it up again. I unfortunately somehow missed @rhettinger's comment on this issue. Will try to give an example as soon as possible. |
@davidhalter ping |
As soon as possible doesn't mean I have time immediately. It will happen and it's still on my radar. Sorry, but I have been quite busy. |
Here's my example:
Output:
The @iritkatriel @rhettinger Does this make sense? In case you think it's a bug as well, I'm happy to create a pull request with my patch & a unit test of the |
Thanks @davidhalter. I agree that this looks like a bug. Just to give a slightly shorter reproducer: >>> class DescriptorGetDelete:
... def __get__(self, instance, klass):
... return 'foo'
... def __delete__(self, instance, klass): pass
...
>>> class Foo:
... get_delete = DescriptorGetDelete()
... def __init__(self):
... self.__dict__['get_delete'] = 42
...
>>> foo = Foo()
>>> foo.get_delete
'foo'
>>> import inspect
>>> inspect.getattr_static(foo, 'get_delete')
42 The result of the last call should probably be If you file a PR for this issue, feel free to ping me on it -- I'd be happy to review it. |
The fix here is simply to also check for To be clear, despite the resolution of #70291 (which I think was resolved incorrectly), the check for |
…04517) Co-authored-by: Carl Meyer <[email protected]>
…ic (pythonGH-104517) (cherry picked from commit 5e9f471) Co-authored-by: Furkan Onder <[email protected]> Co-authored-by: Carl Meyer <[email protected]>
…tic (GH-104517) (#104557) gh-75367: Fix data descriptor detection in inspect.getattr_static (GH-104517) (cherry picked from commit 5e9f471) Co-authored-by: Furkan Onder <[email protected]> Co-authored-by: Carl Meyer <[email protected]>
* main: (26 commits) pythonGH-101520: Move tracemalloc functionality into core, leaving interface in Modules. (python#104508) typing: Add more tests for TypeVar (python#104571) pythongh-104572: Improve error messages for invalid constructs in PEP 695 contexts (python#104573) typing: Use PEP 695 syntax in typing.py (python#104553) pythongh-102153: Start stripping C0 control and space chars in `urlsplit` (python#102508) pythongh-104469: Update README.txt for _testcapi (pythongh-104529) pythonGH-103092: isolate `_elementtree` (python#104561) pythongh-104050: Add typing to Argument Clinic converters (python#104547) pythonGH-103906: Remove immortal refcounting in the interpreter (pythonGH-103909) pythongh-87474: Fix file descriptor leaks in subprocess.Popen (python#96351) pythonGH-103092: isolate `pyexpat` (python#104506) pythongh-75367: Fix data descriptor detection in inspect.getattr_static (python#104517) pythongh-104050: Add more annotations to `Tools/clinic.py` (python#104544) pythongh-104555: Fix isinstance() and issubclass() for runtime-checkable protocols that use PEP 695 (python#104556) pythongh-103865: add monitoring support to LOAD_SUPER_ATTR (python#103866) CODEOWNERS: Assign new PEP 695 files to myself (python#104551) pythonGH-104510: Fix refleaks in `_io` base types (python#104516) pythongh-104539: Fix indentation error in logging.config.rst (python#104545) pythongh-104050: Don't star-import 'types' in Argument Clinic (python#104543) pythongh-104050: Add basic typing to CConverter in clinic.py (python#104538) ...
@carljm The issue seems to have been resolved. We can close the issue. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: