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
95801bbe
Kaydet (Commit)
95801bbe
authored
Agu 19, 2015
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #24879: Teach pydoc to display named tuple fields in the order they were defined.
üst
15b87bfe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
4 deletions
+35
-4
pydoc.py
Lib/pydoc.py
+15
-4
test_pydoc.py
Lib/test/test_pydoc.py
+16
-0
NEWS
Misc/NEWS
+4
-0
No files found.
Lib/pydoc.py
Dosyayı görüntüle @
95801bbe
...
...
@@ -209,6 +209,18 @@ def classify_class_attrs(object):
results
.
append
((
name
,
kind
,
cls
,
value
))
return
results
def
sort_attributes
(
attrs
,
object
):
'Sort the attrs list in-place by _fields and then alphabetically by name'
# This allows data descriptors to be ordered according
# to a _fields attribute if present.
fields
=
getattr
(
object
,
'_fields'
,
[])
try
:
field_order
=
{
name
:
i
-
len
(
fields
)
for
(
i
,
name
)
in
enumerate
(
fields
)}
except
TypeError
:
field_order
=
{}
keyfunc
=
lambda
attr
:
(
field_order
.
get
(
attr
[
0
],
0
),
attr
[
0
])
attrs
.
sort
(
key
=
keyfunc
)
# ----------------------------------------------------- module manipulation
def
ispackage
(
path
):
...
...
@@ -867,8 +879,7 @@ class HTMLDoc(Doc):
object
.
__module__
)
tag
+=
':<br>
\n
'
# Sort attrs by name.
attrs
.
sort
(
key
=
lambda
t
:
t
[
0
])
sort_attributes
(
attrs
,
object
)
# Pump out the attrs, segregated by kind.
attrs
=
spill
(
'Methods
%
s'
%
tag
,
attrs
,
...
...
@@ -1286,8 +1297,8 @@ location listed above.
else
:
tag
=
"inherited from
%
s"
%
classname
(
thisclass
,
object
.
__module__
)
# Sort attrs by name.
attrs
.
sort
(
)
sort_attributes
(
attrs
,
object
)
# Pump out the attrs, segregated by kind.
attrs
=
spill
(
"Methods
%
s:
\n
"
%
tag
,
attrs
,
...
...
Lib/test/test_pydoc.py
Dosyayı görüntüle @
95801bbe
...
...
@@ -811,6 +811,22 @@ class TestDescriptions(unittest.TestCase):
self
.
assertEqual
(
self
.
_get_summary_line
(
t
.
wrap
),
"wrap(text) method of textwrap.TextWrapper instance"
)
def
test_field_order_for_named_tuples
(
self
):
Person
=
namedtuple
(
'Person'
,
[
'nickname'
,
'firstname'
,
'agegroup'
])
s
=
pydoc
.
render_doc
(
Person
)
self
.
assertLess
(
s
.
index
(
'nickname'
),
s
.
index
(
'firstname'
))
self
.
assertLess
(
s
.
index
(
'firstname'
),
s
.
index
(
'agegroup'
))
class
NonIterableFields
:
_fields
=
None
class
NonHashableFields
:
_fields
=
[[]]
# Make sure these doesn't fail
pydoc
.
render_doc
(
NonIterableFields
)
pydoc
.
render_doc
(
NonHashableFields
)
@requires_docstrings
def
test_bound_builtin_method
(
self
):
s
=
StringIO
()
...
...
Misc/NEWS
Dosyayı görüntüle @
95801bbe
...
...
@@ -26,6 +26,10 @@ Library
header
in
part
headers
.
Patch
written
by
Peter
Landry
and
reviewed
by
Pierre
Quentel
.
-
Issue
#
24879
:
help
()
and
pydoc
can
now
list
named
tuple
fields
in
the
order
they
were
defined
rather
than
alphabetically
.
The
ordering
is
determined
by
the
_fields
attribute
if
present
.
-
Issue
#
24774
:
Fix
docstring
in
http
.
server
.
test
.
Patch
from
Chiu
-
Hsiang
Hsu
.
-
Issue
#
21159
:
Improve
message
in
configparser
.
InterpolationMissingOptionError
.
...
...
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