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
c4e0d982
Kaydet (Commit)
c4e0d982
authored
Nis 14, 2013
tarafından
Nick Coghlan
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Close issue #16163: handle submodules in pkgutil.iter_importers
üst
8157459d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
2 deletions
+44
-2
pkgutil.py
Lib/pkgutil.py
+2
-2
test_pkgutil.py
Lib/test/test_pkgutil.py
+39
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pkgutil.py
Dosyayı görüntüle @
c4e0d982
...
...
@@ -451,8 +451,8 @@ def iter_importers(fullname=""):
if
'.'
in
fullname
:
# Get the containing package's __path__
pkg_name
=
fullname
.
rpartition
(
"."
)[
0
]
pkg
=
importlib
.
import_module
(
pkg
)
path
=
getattr
(
sys
.
modules
[
pkg
]
,
'__path__'
,
None
)
pkg
=
importlib
.
import_module
(
pkg
_name
)
path
=
getattr
(
pkg
,
'__path__'
,
None
)
if
path
is
None
:
return
else
:
...
...
Lib/test/test_pkgutil.py
Dosyayı görüntüle @
c4e0d982
...
...
@@ -2,6 +2,7 @@ from test.support import run_unittest, unload, check_warnings
import
unittest
import
sys
import
imp
import
importlib
import
pkgutil
import
os
import
os.path
...
...
@@ -187,6 +188,44 @@ class ExtendPathTests(unittest.TestCase):
del
sys
.
modules
[
'foo.bar'
]
del
sys
.
modules
[
'foo.baz'
]
# Another awful testing hack to be cleaned up once the test_runpy
# helpers are factored out to a common location
def
test_iter_importers
(
self
):
iter_importers
=
pkgutil
.
iter_importers
get_importer
=
pkgutil
.
get_importer
pkgname
=
'spam'
modname
=
'eggs'
dirname
=
self
.
create_init
(
pkgname
)
pathitem
=
os
.
path
.
join
(
dirname
,
pkgname
)
fullname
=
'{}.{}'
.
format
(
pkgname
,
modname
)
try
:
self
.
create_submodule
(
dirname
,
pkgname
,
modname
,
0
)
importlib
.
import_module
(
fullname
)
importers
=
list
(
iter_importers
(
fullname
))
expected_importer
=
get_importer
(
pathitem
)
for
finder
in
importers
:
self
.
assertIsInstance
(
finder
,
importlib
.
machinery
.
FileFinder
)
self
.
assertEqual
(
finder
,
expected_importer
)
self
.
assertIsInstance
(
finder
.
find_module
(
fullname
),
importlib
.
machinery
.
SourceFileLoader
)
self
.
assertIsNone
(
finder
.
find_module
(
pkgname
))
with
self
.
assertRaises
(
ImportError
):
list
(
iter_importers
(
'invalid.module'
))
with
self
.
assertRaises
(
ImportError
):
list
(
iter_importers
(
'.spam'
))
finally
:
shutil
.
rmtree
(
dirname
)
del
sys
.
path
[
0
]
del
sys
.
modules
[
'spam'
]
del
sys
.
modules
[
'spam.eggs'
]
def
test_mixed_namespace
(
self
):
pkgname
=
'foo'
dirname_0
=
self
.
create_init
(
pkgname
)
...
...
Misc/NEWS
Dosyayı görüntüle @
c4e0d982
...
...
@@ -29,6 +29,9 @@ Core and Builtins
Library
-------
-
Issue
#
16163
:
Make
the
importlib
based
version
of
pkgutil
.
iter_importers
work
for
submodules
.
Initial
patch
by
Berker
Peksag
.
-
Issue
#
16804
:
Fix
a
bug
in
the
'site'
module
that
caused
running
'python -S -m site'
to
incorrectly
throw
an
exception
.
...
...
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