Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ec1ddc

Browse files
committed
_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.
1 parent 1eb1fb8 commit 0ec1ddc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Lib/sets.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,16 @@ def _update(self, iterable):
319319
data.update(iterable)
320320
return
321321

322-
value = True
322+
# If the mere process of iterating may raise TypeError, materialize
323+
# the iterable into a tuple first. Then the TypeError will get
324+
# raised here and propagated back to the caller. Once we get into
325+
# the loop following, TypeError is assumed to mean that element
326+
# can't be used as a dict key.
323327
if type(iterable) not in (list, tuple, dict, file, xrange, str):
324-
iterable = list(iterable)
328+
iterable = tuple(iterable)
329+
325330
it = iter(iterable)
331+
value = True
326332
while True:
327333
try:
328334
for element in it:

0 commit comments

Comments
 (0)