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
86f093f7
Unverified
Kaydet (Commit)
86f093f7
authored
Şub 21, 2019
tarafından
Raymond Hettinger
Kaydeden (comit)
GitHub
Şub 21, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-36060: Document how collections.ChainMap() determines iteration order (GH-11969)
üst
7463884f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
collections.rst
Doc/library/collections.rst
+15
-0
test_collections.py
Lib/test/test_collections.py
+14
-0
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
86f093f7
...
@@ -100,6 +100,21 @@ The class can be used to simulate nested scopes and is useful in templating.
...
@@ -100,6 +100,21 @@ The class can be used to simulate nested scopes and is useful in templating.
:func:`super` function. A reference to ``d.parents`` is equivalent to:
:func:`super` function. A reference to ``d.parents`` is equivalent to:
``ChainMap(*d.maps[1:])``.
``ChainMap(*d.maps[1:])``.
Note, the iteration order of a :class:`ChainMap()` is determined by
scanning the mappings last to first::
>>> baseline = {'music': 'bach', 'art': 'rembrandt'}
>>> adjustments = {'art': 'van gogh', 'opera': 'carmen'}
>>> list(ChainMap(adjustments, baseline))
['music', 'art', 'opera']
This gives the same ordering as a series of :meth:`dict.update` calls
starting with the last mapping::
>>> combined = baseline.copy()
>>> combined.update(adjustments)
>>> list(combined)
['music', 'art', 'opera']
.. seealso::
.. seealso::
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
86f093f7
...
@@ -113,6 +113,20 @@ class TestChainMap(unittest.TestCase):
...
@@ -113,6 +113,20 @@ class TestChainMap(unittest.TestCase):
self
.
assertEqual
(
f
[
'b'
],
5
)
# find first in chain
self
.
assertEqual
(
f
[
'b'
],
5
)
# find first in chain
self
.
assertEqual
(
f
.
parents
[
'b'
],
2
)
# look beyond maps[0]
self
.
assertEqual
(
f
.
parents
[
'b'
],
2
)
# look beyond maps[0]
def
test_ordering
(
self
):
# Combined order matches a series of dict updates from last to first.
# This test relies on the ordering of the underlying dicts.
baseline
=
{
'music'
:
'bach'
,
'art'
:
'rembrandt'
}
adjustments
=
{
'art'
:
'van gogh'
,
'opera'
:
'carmen'
}
cm
=
ChainMap
(
adjustments
,
baseline
)
combined
=
baseline
.
copy
()
combined
.
update
(
adjustments
)
self
.
assertEqual
(
list
(
combined
.
items
()),
list
(
cm
.
items
()))
def
test_constructor
(
self
):
def
test_constructor
(
self
):
self
.
assertEqual
(
ChainMap
()
.
maps
,
[{}])
# no-args --> one new dict
self
.
assertEqual
(
ChainMap
()
.
maps
,
[{}])
# no-args --> one new dict
self
.
assertEqual
(
ChainMap
({
1
:
2
})
.
maps
,
[{
1
:
2
}])
# 1 arg --> list
self
.
assertEqual
(
ChainMap
({
1
:
2
})
.
maps
,
[{
1
:
2
}])
# 1 arg --> list
...
...
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