summaryrefslogtreecommitdiffstats
path: root/Lib/sets.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-11-08 05:26:52 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-11-08 05:26:52 (GMT)
commit0ec1ddcdcfaef4a4525f3f8a26d59804deef767d (patch)
tree56d9ce81c2dae53745de50806d1c78afd6f25620 /Lib/sets.py
parent1eb1fb814b4d5ea12dcffd18bb132a1313a48ccf (diff)
downloadcpython-0ec1ddcdcfaef4a4525f3f8a26d59804deef767d.zip
cpython-0ec1ddcdcfaef4a4525f3f8a26d59804deef767d.tar.gz
cpython-0ec1ddcdcfaef4a4525f3f8a26d59804deef767d.tar.bz2
_update(): Commented the new obscurity. Materialized into a tuple
instead of into a list for a bit of speed/space savings. Reopened the bug report too (628246), as I'm unclear on why we don't sort out the cause of the TypeError instead.
Diffstat (limited to 'Lib/sets.py')
-rw-r--r--Lib/sets.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/sets.py b/Lib/sets.py
index bbb93a0..5a66a2e 100644
--- a/Lib/sets.py
+++ b/Lib/sets.py
@@ -319,10 +319,16 @@ class BaseSet(object):
data.update(iterable)
return
- value = True
+ # If the mere process of iterating may raise TypeError, materialize
+ # the iterable into a tuple first. Then the TypeError will get
+ # raised here and propagated back to the caller. Once we get into
+ # the loop following, TypeError is assumed to mean that element
+ # can't be used as a dict key.
if type(iterable) not in (list, tuple, dict, file, xrange, str):
- iterable = list(iterable)
+ iterable = tuple(iterable)
+
it = iter(iterable)
+ value = True
while True:
try:
for element in it: