This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: delattr __slots__ inconsistancy
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.1, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, ferringb
Priority: normal Keywords:

Created on 2009-12-30 18:46 by ferringb, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg97051 - (view) Author: Ferringb (ferringb) * Date: 2009-12-30 18:46
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.

class nonslotted(object):
  pass

class slotted(object):
  __slots__ = ("monkeys",)

try:
  ns = nonslotted()
  assert not hasattr(ns, 'monkeys')
  del ns.monkeys
  raise AssertionError("this is unreachable")
except AttributeError:
  pass
try:
  s = slotted()
  assert not hasattr(s, 'monkeys')
  del s.monkeys
  print "slotting causes delattr to not throw an AttributeError"
  # and now for the kicker
  del s.some_attr_that_is_not_slotted
except AttributeError:
  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__...
msg97055 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-12-30 19:36
Thank you for the report. Fixed in r77157.
msg97057 - (view) Author: Ferringb (ferringb) * Date: 2009-12-30 19:55
Any chance of this landing in py2.7?  It's really a nasty wrench in the
works for some a mapping object essentially maps onto __slots__ for
memory efficiency...
msg97058 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-12-30 19:58
2009/12/30 Brian Harring <report@bugs.python.org>:
>
> Brian Harring <ferringb@gmail.com> added the comment:
>
> Any chance of this landing in py2.7?  It's really a nasty wrench in the
> works for some a mapping object essentially maps onto __slots__ for
> memory efficiency...

It will be in 2.6.5, 2.7, 3.1.2, and 3.2.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51853
2009-12-30 19:58:25benjamin.petersonsetmessages: + msg97058
2009-12-30 19:55:05ferringbsetmessages: + msg97057
2009-12-30 19:36:07benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg97055

resolution: fixed
2009-12-30 18:47:22ferringbsettype: behavior
2009-12-30 18:46:48ferringbcreate