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
45b08293
Kaydet (Commit)
45b08293
authored
Haz 03, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix named tuples to work with vars().
üst
19b851d1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
2 deletions
+7
-2
collections.rst
Doc/library/collections.rst
+3
-1
collections.py
Lib/collections.py
+1
-0
test_collections.py
Lib/test/test_collections.py
+1
-1
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
45b08293
...
@@ -623,7 +623,9 @@ Example:
...
@@ -623,7 +623,9 @@ Example:
'Return a new OrderedDict which maps field names to their values'
'Return a new OrderedDict which maps field names to their values'
return OrderedDict(zip(self._fields, self))
return OrderedDict(zip(self._fields, self))
<BLANKLINE>
<BLANKLINE>
def _replace(_self, **kwds):
__dict__ = property(_asdict)
<BLANKLINE>
def _replace(_self, **kwds):
'Return a new Point object replacing specified fields with new values'
'Return a new Point object replacing specified fields with new values'
result = _self._make(map(kwds.pop, ('x', 'y'), _self))
result = _self._make(map(kwds.pop, ('x', 'y'), _self))
if kwds:
if kwds:
...
...
Lib/collections.py
Dosyayı görüntüle @
45b08293
...
@@ -312,6 +312,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
...
@@ -312,6 +312,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
def _asdict(self):
def _asdict(self):
'Return a new OrderedDict which maps field names to their values'
'Return a new OrderedDict which maps field names to their values'
return OrderedDict(zip(self._fields, self))
\n
return OrderedDict(zip(self._fields, self))
\n
__dict__ = property(_asdict)
\n
def _replace(_self, **kwds):
def _replace(_self, **kwds):
'Return a new
%(typename)
s object replacing specified fields with new values'
'Return a new
%(typename)
s object replacing specified fields with new values'
result = _self._make(map(kwds.pop,
%(field_names)
r, _self))
result = _self._make(map(kwds.pop,
%(field_names)
r, _self))
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
45b08293
...
@@ -78,12 +78,12 @@ class TestNamedTuple(unittest.TestCase):
...
@@ -78,12 +78,12 @@ class TestNamedTuple(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
eval
,
'Point(XXX=1, y=2)'
,
locals
())
# wrong keyword argument
self
.
assertRaises
(
TypeError
,
eval
,
'Point(XXX=1, y=2)'
,
locals
())
# wrong keyword argument
self
.
assertRaises
(
TypeError
,
eval
,
'Point(x=1)'
,
locals
())
# missing keyword argument
self
.
assertRaises
(
TypeError
,
eval
,
'Point(x=1)'
,
locals
())
# missing keyword argument
self
.
assertEqual
(
repr
(
p
),
'Point(x=11, y=22)'
)
self
.
assertEqual
(
repr
(
p
),
'Point(x=11, y=22)'
)
self
.
assertNotIn
(
'__dict__'
,
dir
(
p
))
# verify instance has no dict
self
.
assertNotIn
(
'__weakref__'
,
dir
(
p
))
self
.
assertNotIn
(
'__weakref__'
,
dir
(
p
))
self
.
assertEqual
(
p
,
Point
.
_make
([
11
,
22
]))
# test _make classmethod
self
.
assertEqual
(
p
,
Point
.
_make
([
11
,
22
]))
# test _make classmethod
self
.
assertEqual
(
p
.
_fields
,
(
'x'
,
'y'
))
# test _fields attribute
self
.
assertEqual
(
p
.
_fields
,
(
'x'
,
'y'
))
# test _fields attribute
self
.
assertEqual
(
p
.
_replace
(
x
=
1
),
(
1
,
22
))
# test _replace method
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
(
p
.
_asdict
(),
dict
(
x
=
11
,
y
=
22
))
# test _asdict method
self
.
assertEqual
(
vars
(
p
),
p
.
_asdict
())
# verify that vars() works
try
:
try
:
p
.
_replace
(
x
=
1
,
error
=
2
)
p
.
_replace
(
x
=
1
,
error
=
2
)
...
...
Misc/NEWS
Dosyayı görüntüle @
45b08293
...
@@ -16,6 +16,8 @@ Core and Builtins
...
@@ -16,6 +16,8 @@ Core and Builtins
Library
Library
-------
-------
- Named tuples now work correctly with vars().
- sys.setcheckinterval() now updates the current ticker count as well as updating
- sys.setcheckinterval() now updates the current ticker count as well as updating
the check interval, so if the user decreases the check interval, the ticker
the check interval, so if the user decreases the check interval, the ticker
doesn'
t
have
to
wind
down
to
zero
from
the
old
starting
point
before
the
new
doesn'
t
have
to
wind
down
to
zero
from
the
old
starting
point
before
the
new
...
...
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