Bugs item #1684991, was opened at 2007-03-21 03:53 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1684991&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Documentation Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Georg Brandl (gbrandl) Assigned to: Nobody/Anonymous (nobody) Summary: Explain __method__ lookup semantics for new-style classes Initial Comment: __method__s (and next) are looked up on the type, not the instance. This isn't documented properly. ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2007-04-03 19:21 Message: Logged In: YES user_id=80475 Originator: NO When writing docs, always cover the general case first and thoroughly. Keep the recommendations constructive, positive and useful (as opposed to wording like "this behavior should not be relied upon". A doc patch needs to add clarity -- if it doesn't, leave it out. ---------------------------------------------------------------------- Comment By: Steven Bethard (bediviere) Date: 2007-04-03 17:01 Message: Logged In: YES user_id=945502 Originator: NO This is not true for all __special__ methods, e.g. __enter__ and __exit__: >>> class C(object): ... pass ... >>> def enter(*args): ... print 'enter', args ... >>> def exit(*args): ... print 'exit', args ... >>> c = C() >>> c.__enter__ = enter >>> c.__exit__ = exit >>> with c: ... print 'hi' ... enter () hi exit (None, None, None) The documentation should say something like "When interpreting syntax that invokes a __special__ method, Python looks for the __special__ method on the instance's class. As an implementation detail, the lookup for some __special__ methods may also check the instance first, but this behavior should not be relied upon." This should probably go into the Reference Manual section 3.4: http://docs.python.org/ref/specialnames.html ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1684991&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com