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
7f9f27d7
Kaydet (Commit)
7f9f27d7
authored
Agu 30, 2015
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
merge
üst
46c9c0d6
9157545c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
14 deletions
+15
-14
collections.rst
Doc/library/collections.rst
+3
-3
__init__.py
Lib/collections/__init__.py
+1
-10
test_collections.py
Lib/test/test_collections.py
+11
-1
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
7f9f27d7
...
...
@@ -842,10 +842,10 @@ field names, the method and attribute names start with an underscore.
.. method:: somenamedtuple._asdict()
Return a new :class:`OrderedDict` which maps field names to their corresponding
values. Note, this method is no longer needed now that the same effect can
be achieved by using the built-in :func:`vars` function::
values::
>>> vars(p)
>>> p = Point(x=11, y=22)
>>> p._asdict()
OrderedDict([('x', 11), ('y', 22)])
.. versionchanged:: 3.1
...
...
Lib/collections/__init__.py
Dosyayı görüntüle @
7f9f27d7
...
...
@@ -320,23 +320,14 @@ class {typename}(tuple):
'Return a nicely formatted representation string'
return self.__class__.__name__ + '({repr_fmt})'
%
self
@property
def __dict__(self):
'A new OrderedDict mapping field names to their values'
return OrderedDict(zip(self._fields, self))
def _asdict(self):
'Return a new OrderedDict which maps field names to their values.'
return
self.__dict__
return
OrderedDict(zip(self._fields, self))
def __getnewargs__(self):
'Return self as a plain tuple. Used by copy and pickle.'
return tuple(self)
def __getstate__(self):
'Exclude the OrderedDict from pickling'
return None
{field_defs}
"""
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
7f9f27d7
...
...
@@ -257,7 +257,6 @@ class TestNamedTuple(unittest.TestCase):
self
.
assertEqual
(
p
.
_fields
,
(
'x'
,
'y'
))
# test _fields attribute
self
.
assertEqual
(
p
.
_replace
(
x
=
1
),
(
1
,
22
))
# test _replace method
self
.
assertEqual
(
p
.
_asdict
(),
dict
(
x
=
11
,
y
=
22
))
# test _asdict method
self
.
assertEqual
(
vars
(
p
),
p
.
_asdict
())
# verify that vars() works
try
:
p
.
_replace
(
x
=
1
,
error
=
2
)
...
...
@@ -412,6 +411,17 @@ class TestNamedTuple(unittest.TestCase):
globals
()
.
pop
(
'NTColor'
,
None
)
# clean-up after this test
def
test_namedtuple_subclass_issue_24931
(
self
):
class
Point
(
namedtuple
(
'_Point'
,
[
'x'
,
'y'
])):
pass
a
=
Point
(
3
,
4
)
self
.
assertEqual
(
a
.
_asdict
(),
OrderedDict
([(
'x'
,
3
),
(
'y'
,
4
)]))
a
.
w
=
5
self
.
assertEqual
(
a
.
__dict__
,
{
'w'
:
5
})
################################################################################
### Abstract Base Classes
################################################################################
...
...
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