[New-bugs-announce] [issue7604] delattr __slots__ inconsistancy
report at bugs.python.org
Wed Dec 30 19:46:49 CET 2009
New submission from Brian Harring <ferringb at gmail.com>:
Everything I've read about __slots__, seen w/ them, etc, they're
effectively just a change in the underlying allocation- yes they can
limit the attributes, but that's about it.
Specifically, for general attribute access/mangling, best I can tell,
they're *supposed* to be exactly equivalent when manipulating the
object- the only difference being the backing store.
That said, delattr against slotted objects vs non slotted differs in a
rather buggy way- even worse, the behaviour differs on slotted classes
dependant on if you're delattr'ing a slotted attr or a nonslotted-
consider the following code.
__slots__ = ("monkeys",)
ns = nonslotted()
assert not hasattr(ns, 'monkeys')
raise AssertionError("this is unreachable")
s = slotted()
assert not hasattr(s, 'monkeys')
print "slotting causes delattr to not throw an AttributeError"
# and now for the kicker
print "so... delattr results in AttributeError on a non-slotted attr,
but throws no AttributeError on a slotted attr..."
I'm guessing this isn't intentional/desired?
Confirmed on py2.6/py3.1 also; that said, I'd assume it affects all
versions of python that support __slots__...
components: Interpreter Core
title: delattr __slots__ inconsistancy
versions: Python 2.6, Python 3.1
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce