[issue2778] set_swap_bodies is unsafe

2008-05-14 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: There is no temporary hashability. The hash value is calculated, but never stored in the set's hash field, so it will never become out of sync. Modification while __hash__ or __eq__ is running is possible, but for __eq__ that applies to any muta

[issue2778] set_swap_bodies is unsafe

2008-05-14 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: By replacing temporary immutability with temporary hashability, does this approach create the possibility that someone could mutate the key- set during a search? Is it possible to get the __eq__ check out-of- sync with the __hash__ value?

[issue2778] set_swap_bodies is unsafe

2008-05-14 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: Revised again. sets are only hashed after PyObject_Hash raises a TypeError. This also fixes a regression in test_subclass_with_custom_hash. Oddly, it doesn't show up in trunk, but does when my previous patch is applied to py3k. Added file: htt

[issue2778] set_swap_bodies is unsafe

2008-05-12 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: Here's another approach to avoiding set_swap_bodies. The existing semantics are retained. Rather than creating a temporary frozenset and swapping the contents, I check for a set and call the internal hash function directly (bypassing PyObject_Ha

[issue2778] set_swap_bodies is unsafe

2008-05-08 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: So why doesn't set() in {} work? Why was PEP 351 rejected when it would do this properly? __ Tracker <[EMAIL PROTECTED]> __ __

[issue2778] set_swap_bodies is unsafe

2008-05-08 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Sorry, you don't like the search with autopromotion feature. It has been around since sets were first coded in C. It is a natural extension/consequence of the idea that frozenset('abc')==set('abc'). __ Tr

[issue2778] set_swap_bodies is unsafe

2008-05-08 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: Nevermind that the current implementation *is* broken, even if you consider fixing it to be a low priority. Closing the report with a doc tweak isn't right. __ Tracker <[EMAIL PROTECTED]>

[issue2778] set_swap_bodies is unsafe

2008-05-08 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: I've been unable to find any discussion on this feature. If anything, I think when PEP 218 was discussed and accepted (and PEP 351 rejected), the assumption was it didn't exist. Adding it now should be regarded as a new feature and discussed on

[issue2778] set_swap_bodies is unsafe

2008-05-08 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Added documentation in r62873. Leaving the code as-is. -- resolution: -> fixed status: open -> closed __ Tracker <[EMAIL PROTECTED]>

[issue2778] set_swap_bodies is unsafe

2008-05-07 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: If needed, I'll update the PEP to be more clear. The sets.py module had two protocols: __as_immutable__() and __as_temporarily_immutable__ (). The first protocol was the one that was dropped -- it triggered with something like "s1.add(s

[issue2778] set_swap_bodies is unsafe

2008-05-07 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: PEP 218 explicitly dropped auto-conversion as a feature. Why should this be an exception? __ Tracker <[EMAIL PROTECTED]> __ __

[issue2778] set_swap_bodies is unsafe

2008-05-07 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Rejecting this patch which simply disables a feature that some users consider to be important. I will look at it further. Right now, I'm inclined to simply document that the three temporary autoconversions deny meaningful contemporaneo

[issue2778] set_swap_bodies is unsafe

2008-05-07 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: I decided not to wait. Here's a patch. Several of set's unit tests covered the auto-conversion, so I've modified them. -- keywords: +patch Added file: http://bugs.python.org/file10217/python-setswap.diff ___

[issue2778] set_swap_bodies is unsafe

2008-05-07 Thread Adam Olsen
Adam Olsen <[EMAIL PROTECTED]> added the comment: The intended use is unsafe. contains, remove, and discard all use it for a lookup, which can't be fixed. Upon further inspection, intersection_update is fine. Only a temporary set (not frozenset!) is given junk, which I don't see as a problem.

[issue2778] set_swap_bodies is unsafe

2008-05-07 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: set_swap_bodies() is fine as it involves pure C with no possible callbacks. The issue is in its use in the __contains__() check. I'll take a look at it and see what if anything needs to be changed. Am lowering the priority because yo

[issue2778] set_swap_bodies is unsafe

2008-05-06 Thread Benjamin Peterson
Changes by Benjamin Peterson <[EMAIL PROTECTED]>: -- assignee: -> rhettinger nosy: +rhettinger __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bug

[issue2778] set_swap_bodies is unsafe

2008-05-06 Thread Adam Olsen
New submission from Adam Olsen <[EMAIL PROTECTED]>: set_swap_bodies() is used to cheaply create a frozenset from a set, which is then used for lookups within a set. It does this by creating a temporary empty frozenset, swapping its contents with the original set, doing the lookup using the froze