]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_update(): Commented the new obscurity. Materialized into a tuple
authorTim Peters <tim.peters@gmail.com>
Fri, 8 Nov 2002 05:26:52 +0000 (05:26 +0000)
committerTim Peters <tim.peters@gmail.com>
Fri, 8 Nov 2002 05:26:52 +0000 (05:26 +0000)
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.

Lib/sets.py

index bbb93a091ebd7c2976e0a63fa630650500fac647..5a66a2e0a6612fc5e17412a034729b7882224cc4 100644 (file)
@@ -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: