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.

Author Rhamphoryncus
Recipients Rhamphoryncus
Date 2008-05-07.02:19:24
SpamBayes Score 0.025078043
Marked as misclassified No
Message-id <1210126771.92.0.606864994525.issue2778@psf.upfronthosting.co.za>
In-reply-to
Content
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 frozenset, then swapping the contents back
and releasing the temporary frozenset.

Unfortunately, the lookup can invoke arbitrary code, which may examine
the original set and find it empty (until the lookup completes).  The
lookup may also save a reference to the temporary frozenset, which
mutates to being empty after the lookup completes.

The purpose seems to be allowing "someset in someotherset" to
automatically convert someset to a frozenset.  A brief search didn't
reveal a rationale for this, and in fact PEP 218's history section
claims the opposite: "Auto-conversion between mutable and immutable sets
was dropped."  Perhaps this is a forgotten vestige of that?

set_intersection_update uses set_swap_bodies for a different purpose and
it may be safe.  It depends on whether subclasses of set may retain a
reference to the tmp set somehow.
History
Date User Action Args
2008-05-07 02:19:32Rhamphoryncussetspambayes_score: 0.025078 -> 0.025078043
recipients: + Rhamphoryncus
2008-05-07 02:19:32Rhamphoryncussetspambayes_score: 0.025078 -> 0.025078
messageid: <1210126771.92.0.606864994525.issue2778@psf.upfronthosting.co.za>
2008-05-07 02:19:30Rhamphoryncuslinkissue2778 messages
2008-05-07 02:19:29Rhamphoryncuscreate