This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: builtin_function_or_method's __getattribute__ not applicable to self
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.snow, t184256
Priority: normal Keywords:

Created on 2016-09-24 20:13 by t184256, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
getattribute.py t184256, 2016-09-24 20:13
Messages (3)
msg277332 - (view) Author: Alexander Sosedkin (t184256) Date: 2016-09-24 20:13
I've managed to obtain several objects, which __getattribute__ cannot be applied to them.

Minimal non-working example (a more detailed one is attached):
b = abs.__class__
b.__getattribute__(b, 'x')

Proxying such objects turned out to be even harder that proxying everything else in Python (as if it wasn't already mindbogglingly hard).

As you can see, given that 'builtin_function_or_method' object you can obtain its __getattribute__, but you cannot apply it.

Tested with Python 3.5.2 and 3.6.0b1.

What's the deal with that broken __getattribute__? It seems to be specific to 'builtin_function_or_method' class, but why is it broken? If it is "PyObject_GenericGetAttr", then why object.__getattribute__(b, 'x') works? What am I missing?
msg277338 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2016-09-24 21:52
Hmm.  It's not clear what you're after here.  The error from your example code is correct.  The valid invocation is:

b.__getattribute__(abs, 'x')

That works just fine.  If you want to look up *class* attributes then you must call __getattribute__ on the class's class:

type(b).__getattribute__(b, 'x')

This is how attribute lookup works.  I recommend closing this as not-a-bug.  If you have further question your best bet is to ask on the python-list mailing list.
msg277345 - (view) Author: Alexander Sosedkin (t184256) Date: 2016-09-25 04:58
Oh, I see. The invocation b.__getattribute__(b, attrname) worked on so many objects that I didn't even think it could be incorrect.

Sorry for wasting your time.
History
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72452
2016-09-25 04:58:02t184256setstatus: pending -> closed
resolution: not a bug
messages: + msg277345
2016-09-24 21:52:27eric.snowsetstatus: open -> pending
nosy: + eric.snow
messages: + msg277338

2016-09-24 20:13:55t184256create