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
3215a6c5
Kaydet (Commit)
3215a6c5
authored
May 19, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use dataclass for pkgutil.ModuleInfo
üst
f665b96e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
7 deletions
+46
-7
pkgutil.rst
Doc/library/pkgutil.rst
+1
-1
pkgutil.py
Lib/pkgutil.py
+27
-4
test_pkgutil.py
Lib/test/test_pkgutil.py
+16
-2
2019-05-19-06-19-19.bpo-36962.Yzh0BG.rst
...S.d/next/Library/2019-05-19-06-19-19.bpo-36962.Yzh0BG.rst
+2
-0
No files found.
Doc/library/pkgutil.rst
Dosyayı görüntüle @
3215a6c5
...
@@ -13,7 +13,7 @@ support.
...
@@ -13,7 +13,7 @@ support.
..
class
::
ModuleInfo
(
module_finder
,
name
,
ispkg
)
..
class
::
ModuleInfo
(
module_finder
,
name
,
ispkg
)
A
namedtuple
that
holds
a
brief
summary
of
a
module
's info.
A
dataclass
that
holds
a
brief
summary
of
a
module
's info.
.. versionadded:: 3.6
.. versionadded:: 3.6
...
...
Lib/pkgutil.py
Dosyayı görüntüle @
3215a6c5
"""Utilities to support packages."""
"""Utilities to support packages."""
from
__future__
import
annotations
from
collections
import
named
tuple
from
dataclasses
import
dataclass
,
field
,
as
tuple
from
functools
import
singledispatch
as
simplegeneric
from
functools
import
singledispatch
as
simplegeneric
import
importlib
import
importlib
import
importlib.util
import
importlib.util
...
@@ -19,9 +19,32 @@ __all__ = [
...
@@ -19,9 +19,32 @@ __all__ = [
]
]
ModuleInfo
=
namedtuple
(
'ModuleInfo'
,
'module_finder name ispkg'
)
@dataclass
(
frozen
=
True
,
order
=
True
)
ModuleInfo
.
__doc__
=
'A namedtuple with minimal info about a module.'
class
ModuleInfo
:
"""A dataclass with minimal info about a module."""
module_finder
:
FileFinder
=
field
(
compare
=
False
)
name
:
str
ispkg
:
bool
def
__contains__
(
self
,
item
):
warnings
.
warn
(
"Sequence access is deprecated, use attribute access instead"
,
DeprecationWarning
)
return
item
in
astuple
(
self
)
def
__len__
(
self
):
warnings
.
warn
(
"Sequence access is deprecated, use attribute access instead"
,
DeprecationWarning
)
return
len
(
astuple
(
self
))
def
__iter__
(
self
):
warnings
.
warn
(
"Sequence access is deprecated, use attribute access instead"
,
DeprecationWarning
)
return
iter
(
astuple
(
self
))
def
__getitem__
(
self
,
item
):
warnings
.
warn
(
"Sequence access is deprecated, use attribute access instead"
,
DeprecationWarning
)
return
astuple
(
self
)[
item
]
def
_get_spec
(
finder
,
name
):
def
_get_spec
(
finder
,
name
):
"""Return the finder-specific module spec."""
"""Return the finder-specific module spec."""
...
...
Lib/test/test_pkgutil.py
Dosyayı görüntüle @
3215a6c5
...
@@ -133,7 +133,7 @@ class PkgutilTests(unittest.TestCase):
...
@@ -133,7 +133,7 @@ class PkgutilTests(unittest.TestCase):
'test_walkpackages_filesys.sub'
,
'test_walkpackages_filesys.sub'
,
'test_walkpackages_filesys.sub.mod'
,
'test_walkpackages_filesys.sub.mod'
,
]
]
actual
=
[
e
[
1
]
for
e
in
pkgutil
.
walk_packages
([
self
.
dirname
])]
actual
=
[
e
.
name
for
e
in
pkgutil
.
walk_packages
([
self
.
dirname
])]
self
.
assertEqual
(
actual
,
expected
)
self
.
assertEqual
(
actual
,
expected
)
for
pkg
in
expected
:
for
pkg
in
expected
:
...
@@ -167,7 +167,7 @@ class PkgutilTests(unittest.TestCase):
...
@@ -167,7 +167,7 @@ class PkgutilTests(unittest.TestCase):
'test_walkpackages_zipfile.sub'
,
'test_walkpackages_zipfile.sub'
,
'test_walkpackages_zipfile.sub.mod'
,
'test_walkpackages_zipfile.sub.mod'
,
]
]
actual
=
[
e
[
1
]
for
e
in
pkgutil
.
walk_packages
([
zip_file
])]
actual
=
[
e
.
name
for
e
in
pkgutil
.
walk_packages
([
zip_file
])]
self
.
assertEqual
(
actual
,
expected
)
self
.
assertEqual
(
actual
,
expected
)
del
sys
.
path
[
0
]
del
sys
.
path
[
0
]
...
@@ -229,6 +229,20 @@ class PkgutilPEP302Tests(unittest.TestCase):
...
@@ -229,6 +229,20 @@ class PkgutilPEP302Tests(unittest.TestCase):
self
.
assertEqual
(
foo
.
loads
,
1
)
self
.
assertEqual
(
foo
.
loads
,
1
)
del
sys
.
modules
[
'foo'
]
del
sys
.
modules
[
'foo'
]
def
test_module_info
(
self
):
dummy
=
pkgutil
.
ModuleInfo
(
None
,
'dummy'
,
False
)
with
check_warnings
()
as
w
:
self
.
assertEqual
(
dummy
[
1
],
'dummy'
)
self
.
assertTrue
(
'dummy'
in
dummy
)
self
.
assertEqual
(
len
(
dummy
),
3
)
_
,
name
,
__
=
dummy
self
.
assertEqual
(
name
,
'dummy'
)
self
.
assertEqual
(
len
(
w
.
warnings
),
4
)
self
.
assertEqual
(
dummy
.
name
,
'dummy'
)
dummy2
=
pkgutil
.
ModuleInfo
(
None
,
'dummiest'
,
False
)
self
.
assertTrue
(
dummy
>
dummy2
)
# These tests, especially the setup and cleanup, are hideous. They
# These tests, especially the setup and cleanup, are hideous. They
# need to be cleaned up once issue 14715 is addressed.
# need to be cleaned up once issue 14715 is addressed.
...
...
Misc/NEWS.d/next/Library/2019-05-19-06-19-19.bpo-36962.Yzh0BG.rst
0 → 100644
Dosyayı görüntüle @
3215a6c5
pkgutil.ModuleInfo now a dataclass with rich compare methods instead of a
namedtuple
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