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
d1e768a6
Unverified
Kaydet (Commit)
d1e768a6
authored
Mar 25, 2019
tarafından
Raymond Hettinger
Kaydeden (comit)
GitHub
Mar 25, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-36326: Let inspect.getdoc() find docstrings for __slots__ (GH-12498)
üst
713a8ae7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
3 deletions
+32
-3
3.8.rst
Doc/whatsnew/3.8.rst
+14
-0
inspect.py
Lib/inspect.py
+4
-1
statistics.py
Lib/statistics.py
+2
-1
test_inspect.py
Lib/test/test_inspect.py
+9
-0
test_statistics.py
Lib/test/test_statistics.py
+1
-1
2019-03-22-13-47-52.bpo-36326.WCnEI5.rst
...S.d/next/Library/2019-03-22-13-47-52.bpo-36326.WCnEI5.rst
+2
-0
No files found.
Doc/whatsnew/3.8.rst
Dosyayı görüntüle @
d1e768a6
...
...
@@ -174,6 +174,20 @@ gettext
Added :func:`~gettext.pgettext` and its variants.
(Contributed by Franz Glasner, Éric Araujo, and Cheryl Sabella in :issue:`2504`.)
inspect
-------
The :func:`inspect.getdoc` function can now find docstrings for ``__slots__``
if that attribute is a :class:`dict` where the values are docstrings.
This provides documentation options similar to what we already have
for :func:`property`, :func:`classmethod`, and :func:`staticmethod`::
class AudioClip:
__slots__ = {'bit_rate': 'expressed in kilohertz to one decimal place',
'duration': 'in seconds, rounded up to an integer'}
def __init__(self, bit_rate, duration):
self.bit_rate = round(bit_rate / 1000.0, 1)
self.duration = ceil(duration)
gc
--
...
...
Lib/inspect.py
Dosyayı görüntüle @
d1e768a6
...
...
@@ -582,9 +582,12 @@ def _finddoc(obj):
cls
=
obj
.
__objclass__
if
getattr
(
cls
,
name
)
is
not
obj
:
return
None
if
ismemberdescriptor
(
obj
):
slots
=
getattr
(
cls
,
'__slots__'
,
None
)
if
isinstance
(
slots
,
dict
)
and
name
in
slots
:
return
slots
[
name
]
else
:
return
None
for
base
in
cls
.
__mro__
:
try
:
doc
=
getattr
(
base
,
name
)
.
__doc__
...
...
Lib/statistics.py
Dosyayı görüntüle @
d1e768a6
...
...
@@ -709,7 +709,8 @@ class NormalDist:
# https://en.wikipedia.org/wiki/Normal_distribution
# https://en.wikipedia.org/wiki/Variance#Properties
__slots__
=
(
'mu'
,
'sigma'
)
__slots__
=
{
'mu'
:
'Arithmetic mean of a normal distribution'
,
'sigma'
:
'Standard deviation of a normal distribution'
}
def
__init__
(
self
,
mu
=
0.0
,
sigma
=
1.0
):
'NormalDist where mu is the mean and sigma is the standard deviation.'
...
...
Lib/test/test_inspect.py
Dosyayı görüntüle @
d1e768a6
...
...
@@ -375,6 +375,11 @@ class GetSourceBase(unittest.TestCase):
self
.
assertEqual
(
inspect
.
getsource
(
obj
),
self
.
sourcerange
(
top
,
bottom
))
class
SlotUser
:
'Docstrings for __slots__'
__slots__
=
{
'power'
:
'measured in kilowatts'
,
'distance'
:
'measured in kilometers'
}
class
TestRetrievingSourceCode
(
GetSourceBase
):
fodderModule
=
mod
...
...
@@ -429,6 +434,10 @@ class TestRetrievingSourceCode(GetSourceBase):
'A longer,
\n\n
indented
\n\n
docstring.'
)
self
.
assertEqual
(
inspect
.
getdoc
(
git
.
abuse
),
'Another
\n\n
docstring
\n\n
containing
\n\n
tabs'
)
self
.
assertEqual
(
inspect
.
getdoc
(
SlotUser
.
power
),
'measured in kilowatts'
)
self
.
assertEqual
(
inspect
.
getdoc
(
SlotUser
.
distance
),
'measured in kilometers'
)
@unittest.skipIf
(
sys
.
flags
.
optimize
>=
2
,
"Docstrings are omitted with -O2 and above"
)
...
...
Lib/test/test_statistics.py
Dosyayı görüntüle @
d1e768a6
...
...
@@ -2051,7 +2051,7 @@ class TestNormalDist(unittest.TestCase):
nd
=
statistics
.
NormalDist
(
300
,
23
)
with
self
.
assertRaises
(
TypeError
):
vars
(
nd
)
self
.
assertEqual
(
nd
.
__slots__
,
(
'mu'
,
'sigma'
))
self
.
assertEqual
(
tuple
(
nd
.
__slots__
)
,
(
'mu'
,
'sigma'
))
def
test_instantiation_and_attributes
(
self
):
nd
=
statistics
.
NormalDist
(
500
,
17
)
...
...
Misc/NEWS.d/next/Library/2019-03-22-13-47-52.bpo-36326.WCnEI5.rst
0 → 100644
Dosyayı görüntüle @
d1e768a6
inspect.getdoc() can now find docstrings for member objects when __slots__
is a dictionary.
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