Skip to content
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

delattr __slots__ inconsistancy #51853

Closed
ferringb mannequin opened this issue Dec 30, 2009 · 4 comments
Closed

delattr __slots__ inconsistancy #51853

ferringb mannequin opened this issue Dec 30, 2009 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ferringb
Copy link
Mannequin

ferringb mannequin commented Dec 30, 2009

BPO 7604
Nosy @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-12-30.19:36:07.821>
created_at = <Date 2009-12-30.18:46:47.743>
labels = ['interpreter-core', 'type-bug']
title = 'delattr __slots__ inconsistancy'
updated_at = <Date 2009-12-30.19:58:25.815>
user = 'https://bugs.python.org/ferringb'

bugs.python.org fields:

activity = <Date 2009-12-30.19:58:25.815>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2009-12-30.19:36:07.821>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2009-12-30.18:46:47.743>
creator = 'ferringb'
dependencies = []
files = []
hgrepos = []
issue_num = 7604
keywords = []
message_count = 4.0
messages = ['97051', '97055', '97057', '97058']
nosy_count = 2.0
nosy_names = ['ferringb', 'benjamin.peterson']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue7604'
versions = ['Python 2.6', 'Python 3.1']

@ferringb
Copy link
Mannequin Author

ferringb mannequin commented Dec 30, 2009

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__...

@ferringb ferringb mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Dec 30, 2009
@benjaminp
Copy link
Contributor

Thank you for the report. Fixed in r77157.

@ferringb
Copy link
Mannequin Author

ferringb mannequin commented Dec 30, 2009

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...

@benjaminp
Copy link
Contributor

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant