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

set_contains, etc. should check for collections.Set in addition to PySet_Check #52998

Closed
stutzbach mannequin opened this issue May 18, 2010 · 2 comments
Closed

set_contains, etc. should check for collections.Set in addition to PySet_Check #52998

stutzbach mannequin opened this issue May 18, 2010 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@stutzbach
Copy link
Mannequin

stutzbach mannequin commented May 18, 2010

BPO 8752
Nosy @rhettinger

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 2010-05-18.19:50:52.431>
created_at = <Date 2010-05-18.15:21:11.080>
labels = ['interpreter-core', 'type-bug']
title = 'set_contains, etc. should check for collections.Set in addition to PySet_Check'
updated_at = <Date 2010-05-18.19:50:52.374>
user = 'https://bugs.python.org/stutzbach'

bugs.python.org fields:

activity = <Date 2010-05-18.19:50:52.374>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = <Date 2010-05-18.19:50:52.431>
closer = 'rhettinger'
components = ['Interpreter Core']
creation = <Date 2010-05-18.15:21:11.080>
creator = 'stutzbach'
dependencies = []
files = []
hgrepos = []
issue_num = 8752
keywords = []
message_count = 2.0
messages = ['105983', '106004']
nosy_count = 2.0
nosy_names = ['rhettinger', 'stutzbach']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'test needed'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue8752'
versions = ['Python 2.7', 'Python 3.2']

@stutzbach
Copy link
Mannequin Author

stutzbach mannequin commented May 18, 2010

For operations that test membership in a set, Python coerces sets and subclasses of set into a temporary frozenset before testing membership.

For example, this works:

>>> set() in set([frozenset()])
True

Although the set() is not hashable itself, Python creates a temporary frozenset() out of the set(). It should do the same for user-types derived from collections.Set, so they can inter-operate in the same way.

In setobject.c, the following methods behave in the described manner: set_contains, set_remove, and set_discard.

@stutzbach stutzbach mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels May 18, 2010
@rhettinger
Copy link
Contributor

I don't think the set methods can make assumptions about whether instances of the Set API can be made frozen. It is okay to restrict this to just instances of "set" where we know its internal structure and know that its elements are hashable (see the collections docs for an example of a non-hashable set).

Also, the collections.Set methods are supposed to be minimal. They are not intended to mimic every aspect of regular set objects.

@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