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
e98839a1
Kaydet (Commit)
e98839a1
authored
Haz 09, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue3065: Fixed pickling of named tuples. Added tests.
üst
f4fcdb6b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
collections.rst
Doc/library/collections.rst
+3
-0
collections.py
Lib/collections.py
+3
-1
test_collections.py
Lib/test/test_collections.py
+20
-1
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
e98839a1
...
@@ -539,6 +539,9 @@ Example:
...
@@ -539,6 +539,9 @@ Example:
if kwds:
if kwds:
raise ValueError('Got unexpected field names: %r' % kwds.keys())
raise ValueError('Got unexpected field names: %r' % kwds.keys())
return result
return result
<BLANKLINE>
def __getnewargs__(self):
return tuple(self)
<BLANKLINE>
<BLANKLINE>
x = property(itemgetter(0))
x = property(itemgetter(0))
y = property(itemgetter(1))
y = property(itemgetter(1))
...
...
Lib/collections.py
Dosyayı görüntüle @
e98839a1
...
@@ -82,7 +82,9 @@ def namedtuple(typename, field_names, verbose=False):
...
@@ -82,7 +82,9 @@ def namedtuple(typename, field_names, verbose=False):
result = self._make(map(kwds.pop,
%(field_names)
r, self))
result = self._make(map(kwds.pop,
%(field_names)
r, self))
if kwds:
if kwds:
raise ValueError('Got unexpected field names:
%%
r'
%%
kwds.keys())
raise ValueError('Got unexpected field names:
%%
r'
%%
kwds.keys())
return result
\n\n
'''
%
locals
()
return result
\n
def __getnewargs__(self):
return tuple(self)
\n\n
'''
%
locals
()
for
i
,
name
in
enumerate
(
field_names
):
for
i
,
name
in
enumerate
(
field_names
):
template
+=
'
%
s = property(itemgetter(
%
d))
\n
'
%
(
name
,
i
)
template
+=
'
%
s = property(itemgetter(
%
d))
\n
'
%
(
name
,
i
)
if
verbose
:
if
verbose
:
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
e98839a1
import
unittest
,
doctest
import
unittest
,
doctest
from
test
import
test_support
from
test
import
test_support
from
collections
import
namedtuple
from
collections
import
namedtuple
import
pickle
,
cPickle
,
copy
from
collections
import
Hashable
,
Iterable
,
Iterator
from
collections
import
Hashable
,
Iterable
,
Iterator
from
collections
import
Sized
,
Container
,
Callable
from
collections
import
Sized
,
Container
,
Callable
from
collections
import
Set
,
MutableSet
from
collections
import
Set
,
MutableSet
from
collections
import
Mapping
,
MutableMapping
from
collections
import
Mapping
,
MutableMapping
from
collections
import
Sequence
,
MutableSequence
from
collections
import
Sequence
,
MutableSequence
TestNT
=
namedtuple
(
'TestNT'
,
'x y z'
)
# type used for pickle tests
class
TestNamedTuple
(
unittest
.
TestCase
):
class
TestNamedTuple
(
unittest
.
TestCase
):
...
@@ -108,7 +110,7 @@ class TestNamedTuple(unittest.TestCase):
...
@@ -108,7 +110,7 @@ class TestNamedTuple(unittest.TestCase):
self
.
assertEqual
(
Dot
(
1
)
.
_replace
(
d
=
999
),
(
999
,))
self
.
assertEqual
(
Dot
(
1
)
.
_replace
(
d
=
999
),
(
999
,))
self
.
assertEqual
(
Dot
(
1
)
.
_fields
,
(
'd'
,))
self
.
assertEqual
(
Dot
(
1
)
.
_fields
,
(
'd'
,))
n
=
10
000
n
=
5
000
import
string
,
random
import
string
,
random
names
=
list
(
set
(
''
.
join
([
random
.
choice
(
string
.
ascii_letters
)
names
=
list
(
set
(
''
.
join
([
random
.
choice
(
string
.
ascii_letters
)
for
j
in
range
(
10
)])
for
i
in
range
(
n
)))
for
j
in
range
(
10
)])
for
i
in
range
(
n
)))
...
@@ -130,6 +132,23 @@ class TestNamedTuple(unittest.TestCase):
...
@@ -130,6 +132,23 @@ class TestNamedTuple(unittest.TestCase):
self
.
assertEqual
(
b2
,
tuple
(
b2_expected
))
self
.
assertEqual
(
b2
,
tuple
(
b2_expected
))
self
.
assertEqual
(
b
.
_fields
,
tuple
(
names
))
self
.
assertEqual
(
b
.
_fields
,
tuple
(
names
))
def
test_pickle
(
self
):
p
=
TestNT
(
x
=
10
,
y
=
20
,
z
=
30
)
for
module
in
pickle
,
cPickle
:
loads
=
getattr
(
module
,
'loads'
)
dumps
=
getattr
(
module
,
'dumps'
)
for
protocol
in
-
1
,
0
,
1
,
2
:
q
=
loads
(
dumps
(
p
,
protocol
))
self
.
assertEqual
(
p
,
q
)
self
.
assertEqual
(
p
.
_fields
,
q
.
_fields
)
def
test_copy
(
self
):
p
=
TestNT
(
x
=
10
,
y
=
20
,
z
=
30
)
for
copier
in
copy
.
copy
,
copy
.
deepcopy
:
q
=
copier
(
p
)
self
.
assertEqual
(
p
,
q
)
self
.
assertEqual
(
p
.
_fields
,
q
.
_fields
)
class
TestOneTrickPonyABCs
(
unittest
.
TestCase
):
class
TestOneTrickPonyABCs
(
unittest
.
TestCase
):
def
test_Hashable
(
self
):
def
test_Hashable
(
self
):
...
...
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