mirror of
https://github.com/python/cpython
synced 2024-09-20 15:41:39 +00:00
_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.
This commit is contained in:
parent
1eb1fb814b
commit
0ec1ddcdcf
10
Lib/sets.py
10
Lib/sets.py
|
@ -319,10 +319,16 @@ def _update(self, iterable):
|
||||||
data.update(iterable)
|
data.update(iterable)
|
||||||
return
|
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):
|
if type(iterable) not in (list, tuple, dict, file, xrange, str):
|
||||||
iterable = list(iterable)
|
iterable = tuple(iterable)
|
||||||
|
|
||||||
it = iter(iterable)
|
it = iter(iterable)
|
||||||
|
value = True
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
for element in it:
|
for element in it:
|
||||||
|
|
Loading…
Reference in a new issue