Someone pasted the original version of the following code snippet on
#python today. I started investigating why the new-style class didn't
work as expected, and found that at least some instances of new-style
classes apparently don't return true for PyInstance_Chec k, which causes
a problem in PySequence_Chec k, since it will only do an attribute lookup
for instances.
Things probably shouldn't be this way. Should I go to python-dev with this?
Demonstration snippet:
args={'a':0}
class Args(object):
def __getattr__(sel f,attr):
print "__getattr_ _:", attr
return getattr(args,at tr)
class ClassicArgs:
def __getattr__(sel f, attr):
print "__getattr_ _:", attr
return getattr(args, attr)
if __name__ == '__main__':
c = ClassicArgs()
i = c.__iter__()
print i
i = iter(c)
print i
a = Args()
i = a.__iter__()
print i
i = iter(a)
print i
#python today. I started investigating why the new-style class didn't
work as expected, and found that at least some instances of new-style
classes apparently don't return true for PyInstance_Chec k, which causes
a problem in PySequence_Chec k, since it will only do an attribute lookup
for instances.
Things probably shouldn't be this way. Should I go to python-dev with this?
Demonstration snippet:
args={'a':0}
class Args(object):
def __getattr__(sel f,attr):
print "__getattr_ _:", attr
return getattr(args,at tr)
class ClassicArgs:
def __getattr__(sel f, attr):
print "__getattr_ _:", attr
return getattr(args, attr)
if __name__ == '__main__':
c = ClassicArgs()
i = c.__iter__()
print i
i = iter(c)
print i
a = Args()
i = a.__iter__()
print i
i = iter(a)
print i
Comment