Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7cd83ca9
Kaydet (Commit)
7cd83ca9
authored
Kas 08, 2002
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Another attempt at making the set constructor both safe and fast. [SF
bug 628246]
üst
91e77536
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
18 deletions
+24
-18
sets.py
Lib/sets.py
+24
-18
No files found.
Lib/sets.py
Dosyayı görüntüle @
7cd83ca9
...
...
@@ -319,26 +319,32 @@ class BaseSet(object):
data
.
update
(
iterable
)
return
# 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
=
tuple
(
iterable
)
it
=
iter
(
iterable
)
value
=
True
while
True
:
try
:
for
element
in
it
:
if
type
(
iterable
)
in
(
list
,
tuple
,
xrange
):
# Optimized: we know that __iter__() and next() can't
# raise TypeError, so we can move 'try:' out of the loop.
it
=
iter
(
iterable
)
while
True
:
try
:
for
element
in
it
:
data
[
element
]
=
value
return
except
TypeError
:
transform
=
getattr
(
element
,
"_as_immutable"
,
None
)
if
transform
is
None
:
raise
# re-raise the TypeError exception we caught
data
[
transform
()]
=
value
else
:
# Safe: only catch TypeError where intended
for
element
in
iterable
:
try
:
data
[
element
]
=
value
return
except
TypeError
:
transform
=
getattr
(
element
,
"_as_immutable"
,
None
)
if
transform
is
None
:
raise
# re-raise the TypeError exception we caught
data
[
transform
()]
=
value
except
TypeError
:
transform
=
getattr
(
element
,
"_as_immutable"
,
None
)
if
transform
is
None
:
raise
# re-raise the TypeError exception we caught
data
[
transform
()]
=
value
class
ImmutableSet
(
BaseSet
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment