[Python-3000] special attrs looked up on the type, not instance (original) (raw)

Neal Norwitz nnorwitz at gmail.com
Wed Mar 14 04:19:23 CET 2007


---------- Forwarded message from python-3000-checkins ----------

Neal Norwitz schrieb:

I assume this is not the desired behaviour?

class F: ... def dir(self): ... return [5] ... dir(F()) [5] f = F() dir(f) [5] def dir(): return [10] ... f.dir = dir dir(f) [5] I think the problem is in dirobject() + PyObject * dirfunc = PyObjectGetAttrString((PyObject*)obj->obtype, + "dir"); Shouldn't the first arg just be obj, not obj->obtype?

[Georg] This is modeled after the principle that for new-style objects, special methods are looked up on the type, not the instance.


  1. I didn't remember this, do we have it documented somewhere?
  2. Assuming #1 is correct, is this rule consistently applied?
  3. How does (should) this affect 2.6 and migration to 3.0, if at all?

n



More information about the Python-3000 mailing list