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
Class attributes shadow __slots__
#1
Comments
I don't reproduce this exactly, but the behavior is still odd: >>> class MyProxy(SpecificationDecoratorBase):
... __slots__ = ('foo',)
... foo = None
...
>>> f = MyProxy([])
>>> print f.foo
None
>>> f.foo = 'bar'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'foo' |
I'm not sure this is a bug. You get the same basic thing without involving a proxy: >>> class MyObject(object):
... __slots__ = ('foo',)
... foo = None
...
>>> f = MyObject()
>>> print f.foo
None
>>> f.foo = 'bar'
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'MyObject' object attribute 'foo' is read-only The presence of the >>> MyObject.__dict__
{'__module__': '__main__', '__slots__': ('foo',), 'foo': None, '__doc__': None}
# Compare to an absent class attribute
>>> class MyOtherObject(object):
... __slots__ = ('foo',)
...
>>> MyOtherObject.__dict__
{'foo': <member 'foo' of 'MyOtherObject' objects>, '__slots__': ('foo',), '__module__': '__main__', '__doc__': None} But
Now, where it gets weird in the proxy case is if the underlying object can accept a >>> class Any(object): pass
...
>>> any = Any()
>>> f = MyObject(any)
>>> f.foo
>>> f.foo = 'bar'
>>> f.foo
>>> any.foo
'bar' I'm not sure if that's a genuine bug, or if we're in corner-cases of the language specification because we're trying to use |
In https://bugs.launchpad.net/zope.proxy/+bug/186631, @ctheune reported:
The text was updated successfully, but these errors were encountered: