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
6538b430
Kaydet (Commit)
6538b430
authored
Agu 16, 2016
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #25628: Make namedtuple "rename" and "verbose" parameters keyword-only.
üst
3ee933f1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
3 deletions
+22
-3
collections.rst
Doc/library/collections.rst
+6
-2
__init__.py
Lib/collections/__init__.py
+1
-1
test_collections.py
Lib/test/test_collections.py
+12
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
6538b430
...
@@ -763,7 +763,7 @@ Named tuples assign meaning to each position in a tuple and allow for more reada
...
@@ -763,7 +763,7 @@ Named tuples assign meaning to each position in a tuple and allow for more reada
self-documenting code. They can be used wherever regular tuples are used, and
self-documenting code. They can be used wherever regular tuples are used, and
they add the ability to access fields by name instead of position index.
they add the ability to access fields by name instead of position index.
.. function:: namedtuple(typename, field_names, verbose=False, rename=False)
.. function:: namedtuple(typename, field_names,
*,
verbose=False, rename=False)
Returns a new tuple subclass named *typename*. The new subclass is used to
Returns a new tuple subclass named *typename*. The new subclass is used to
create tuple-like objects that have fields accessible by attribute lookup as
create tuple-like objects that have fields accessible by attribute lookup as
...
@@ -799,7 +799,11 @@ they add the ability to access fields by name instead of position index.
...
@@ -799,7 +799,11 @@ they add the ability to access fields by name instead of position index.
a namedtuple.
a namedtuple.
.. versionchanged:: 3.1
.. versionchanged:: 3.1
Added support for *rename*.
Added support for *rename*.
.. versionchanged:: 3.6
The *verbose* and *rename* parameters became
:ref:`keyword-only arguments <keyword-only_parameter>`.
.. doctest::
.. doctest::
...
...
Lib/collections/__init__.py
Dosyayı görüntüle @
6538b430
...
@@ -353,7 +353,7 @@ _field_template = '''\
...
@@ -353,7 +353,7 @@ _field_template = '''\
{name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}')
{name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}')
'''
'''
def
namedtuple
(
typename
,
field_names
,
verbose
=
False
,
rename
=
False
):
def
namedtuple
(
typename
,
field_names
,
*
,
verbose
=
False
,
rename
=
False
):
"""Returns a new subclass of tuple with named fields.
"""Returns a new subclass of tuple with named fields.
>>> Point = namedtuple('Point', ['x', 'y'])
>>> Point = namedtuple('Point', ['x', 'y'])
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
6538b430
...
@@ -412,6 +412,18 @@ class TestNamedTuple(unittest.TestCase):
...
@@ -412,6 +412,18 @@ class TestNamedTuple(unittest.TestCase):
self
.
assertEqual
(
NTColor
.
_fields
,
(
'red'
,
'green'
,
'blue'
))
self
.
assertEqual
(
NTColor
.
_fields
,
(
'red'
,
'green'
,
'blue'
))
globals
()
.
pop
(
'NTColor'
,
None
)
# clean-up after this test
globals
()
.
pop
(
'NTColor'
,
None
)
# clean-up after this test
def
test_keyword_only_arguments
(
self
):
# See issue 25628
with
support
.
captured_stdout
()
as
template
:
NT
=
namedtuple
(
'NT'
,
[
'x'
,
'y'
],
verbose
=
True
)
self
.
assertIn
(
'class NT'
,
NT
.
_source
)
with
self
.
assertRaises
(
TypeError
):
NT
=
namedtuple
(
'NT'
,
[
'x'
,
'y'
],
True
)
NT
=
namedtuple
(
'NT'
,
[
'abc'
,
'def'
],
rename
=
True
)
self
.
assertEqual
(
NT
.
_fields
,
(
'abc'
,
'_1'
))
with
self
.
assertRaises
(
TypeError
):
NT
=
namedtuple
(
'NT'
,
[
'abc'
,
'def'
],
False
,
True
)
def
test_namedtuple_subclass_issue_24931
(
self
):
def
test_namedtuple_subclass_issue_24931
(
self
):
class
Point
(
namedtuple
(
'_Point'
,
[
'x'
,
'y'
])):
class
Point
(
namedtuple
(
'_Point'
,
[
'x'
,
'y'
])):
...
...
Misc/NEWS
Dosyayı görüntüle @
6538b430
...
@@ -73,6 +73,9 @@ Library
...
@@ -73,6 +73,9 @@ Library
to ref count problem introduced in code for Issue #27038 in 3.6.0a3.
to ref count problem introduced in code for Issue #27038 in 3.6.0a3.
Patch by Xiang Zhang.
Patch by Xiang Zhang.
- Issue #25628: The *verbose* and *rename* parameters for collections.namedtuple
are now keyword-only.
- Issue #12345: Add mathemathical constant tau to math and cmath. See also
- Issue #12345: Add mathemathical constant tau to math and cmath. See also
PEP 628.
PEP 628.
...
...
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