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

improve __getattribute__ documentation #48767

Closed
lambertdw mannequin opened this issue Dec 4, 2008 · 5 comments
Closed

improve __getattribute__ documentation #48767

lambertdw mannequin opened this issue Dec 4, 2008 · 5 comments
Assignees
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@lambertdw
Copy link
Mannequin

lambertdw mannequin commented Dec 4, 2008

BPO 4517
Nosy @birkenfeld

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:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2008-12-05.15:29:44.863>
created_at = <Date 2008-12-04.04:34:58.074>
labels = ['type-feature', 'docs']
title = 'improve __getattribute__ documentation'
updated_at = <Date 2008-12-05.15:29:44.837>
user = 'https://bugs.python.org/LambertDW'

bugs.python.org fields:

activity = <Date 2008-12-05.15:29:44.837>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2008-12-05.15:29:44.863>
closer = 'georg.brandl'
components = ['Documentation']
creation = <Date 2008-12-04.04:34:58.074>
creator = 'LambertDW'
dependencies = []
files = []
hgrepos = []
issue_num = 4517
keywords = []
message_count = 5.0
messages = ['76867', '76868', '77021', '77029', '77030']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'LambertDW']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue4517'
versions = ['Python 3.0']

@lambertdw
Copy link
Mannequin Author

lambertdw mannequin commented Dec 4, 2008

http://docs.python.org/dev/3.0/reference/datamodel.html#special-lookup

(After fixing the link to http://docs.python.org/3.0 at http://www.python.org/doc/ (and likewise the http://docs.python.org/whatsnew/3.0.html link.)...

The comment that __getattribute__ is "Called unconditionally to
implement attribute accesses for instances of the class" gave me hope
that some combination of "meta" "super" and "sub" might let me access
__getattribute__ for expression eval('obj + another_object') despite the
special notes. I realize now the truth is that

"__getattribute__ is NEVER accessible in pure python code when the code
uses the syntax of a unary or binary operator such as a+b, ~a, len(a)."
See most of the functions in this manual section.
Also name hash, which doesn't find much explicit use but could well be
the most used python functionality. Find a smooth way to replace my
NEVER since code can obviously access __getattribute__ from the special
function.

Thank you, and great work!

@lambertdw lambertdw mannequin assigned birkenfeld Dec 4, 2008
@lambertdw lambertdw mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Dec 4, 2008
@lambertdw
Copy link
Mannequin Author

lambertdw mannequin commented Dec 4, 2008

>>> class c:
...  def __getattribute__(self,*args):
...   print('getattribute chimes in')
... 

>>> c()+3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'c' and 'int'

@birkenfeld
Copy link
Member

Isn't what you refer to covered by this paragraph and the following
example: "In addition to bypassing any instance attributes in the
interest of correctness, implicit special method lookup may also bypass
the __getattribute__() method even of the object’s metaclass:"?

@lambertdw
Copy link
Mannequin Author

lambertdw mannequin commented Dec 5, 2008

Yes to msg77021. However!

I'll pin the difficulty specifically to the word "may". This cost me a
lot of time.

  1. Please change the phrasing you quoted to

"... implicit special method lookup bypasses the __getattribute__()
method even of the object’s metaclass:"

  1. Please insert into the glossary a definition of "implicit special
    method lookup" that addresses the grammar or syntax that causes it
    considering monad and dyad use.

Thank you.

@birkenfeld
Copy link
Member

I've changed "may bypass" to "generally bypasses". It doesn't happen for
all methods, but that's an implementation detail.

I've also added a glossary entry "special method" in r67579.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant