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
62b4b9ee
Kaydet (Commit)
62b4b9ee
authored
Mar 04, 2014
tarafından
Nick Coghlan
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Close #20839: pkgutil.find_loader now uses importlib.util.find_spec
üst
01cc2d5f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
21 deletions
+41
-21
pkgutil.rst
Doc/library/pkgutil.rst
+9
-8
pkgutil.py
Lib/pkgutil.py
+5
-12
test_pkgutil.py
Lib/test/test_pkgutil.py
+19
-0
NEWS
Misc/NEWS
+8
-1
No files found.
Doc/library/pkgutil.rst
Dosyayı görüntüle @
62b4b9ee
...
@@ -74,15 +74,17 @@ support.
...
@@ -74,15 +74,17 @@ support.
Retrieve a :pep:`302` module loader for the given *fullname*.
Retrieve a :pep:`302` module loader for the given *fullname*.
This is a
convenience wrapper around :func:`importlib.find_loader` that
This is a
backwards compatibility wrapper around
sets the *path* argument correctly when searching for submodules, and
:func:`importlib.util.find_spec` that converts most failures to
also ensures parent packages (if any) are imported before searching for
:exc:`ImportError` and only returns the loader rather than the full
submodules
.
:class:`ModuleSpec`
.
.. versionchanged:: 3.3
.. versionchanged:: 3.3
Updated to be based directly on :mod:`importlib` rather than relying
Updated to be based directly on :mod:`importlib` rather than relying
on the package internal PEP 302 import emulation.
on the package internal PEP 302 import emulation.
.. versionchanged:: 3.4
Updated to be based on :pep:`451`
.. function:: get_importer(path_item)
.. function:: get_importer(path_item)
...
@@ -109,14 +111,13 @@ support.
...
@@ -109,14 +111,13 @@ support.
not already imported, its containing package (if any) is imported, in order
not already imported, its containing package (if any) is imported, in order
to establish the package ``__path__``.
to establish the package ``__path__``.
This function uses :func:`iter_importers`, and is thus subject to the same
limitations regarding platform-specific special import locations such as the
Windows registry.
.. versionchanged:: 3.3
.. versionchanged:: 3.3
Updated to be based directly on :mod:`importlib` rather than relying
Updated to be based directly on :mod:`importlib` rather than relying
on the package internal PEP 302 import emulation.
on the package internal PEP 302 import emulation.
.. versionchanged:: 3.4
Updated to be based on :pep:`451`
.. function:: iter_importers(fullname='')
.. function:: iter_importers(fullname='')
...
...
Lib/pkgutil.py
Dosyayı görüntüle @
62b4b9ee
...
@@ -470,29 +470,22 @@ def get_loader(module_or_name):
...
@@ -470,29 +470,22 @@ def get_loader(module_or_name):
def
find_loader
(
fullname
):
def
find_loader
(
fullname
):
"""Find a PEP 302 "loader" object for fullname
"""Find a PEP 302 "loader" object for fullname
This is s convenience wrapper around :func:`importlib.find_loader` that
This is a backwards compatibility wrapper around
sets the *path* argument correctly when searching for submodules, and
importlib.util.find_spec that converts most failures to ImportError
also ensures parent packages (if any) are imported before searching for
and only returns the loader rather than the full spec
submodules.
"""
"""
if
fullname
.
startswith
(
'.'
):
if
fullname
.
startswith
(
'.'
):
msg
=
"Relative module name {!r} not supported"
.
format
(
fullname
)
msg
=
"Relative module name {!r} not supported"
.
format
(
fullname
)
raise
ImportError
(
msg
)
raise
ImportError
(
msg
)
path
=
None
pkg_name
=
fullname
.
rpartition
(
"."
)[
0
]
if
pkg_name
:
pkg
=
importlib
.
import_module
(
pkg_name
)
path
=
getattr
(
pkg
,
"__path__"
,
None
)
if
path
is
None
:
return
None
try
:
try
:
return
importlib
.
find_loader
(
fullname
,
path
)
spec
=
importlib
.
util
.
find_spec
(
fullname
)
except
(
ImportError
,
AttributeError
,
TypeError
,
ValueError
)
as
ex
:
except
(
ImportError
,
AttributeError
,
TypeError
,
ValueError
)
as
ex
:
# This hack fixes an impedance mismatch between pkgutil and
# This hack fixes an impedance mismatch between pkgutil and
# importlib, where the latter raises other errors for cases where
# importlib, where the latter raises other errors for cases where
# pkgutil previously raised ImportError
# pkgutil previously raised ImportError
msg
=
"Error while finding loader for {!r} ({}: {})"
msg
=
"Error while finding loader for {!r} ({}: {})"
raise
ImportError
(
msg
.
format
(
fullname
,
type
(
ex
),
ex
))
from
ex
raise
ImportError
(
msg
.
format
(
fullname
,
type
(
ex
),
ex
))
from
ex
return
spec
.
loader
def
extend_path
(
path
,
name
):
def
extend_path
(
path
,
name
):
...
...
Lib/test/test_pkgutil.py
Dosyayı görüntüle @
62b4b9ee
...
@@ -334,6 +334,25 @@ class ImportlibMigrationTests(unittest.TestCase):
...
@@ -334,6 +334,25 @@ class ImportlibMigrationTests(unittest.TestCase):
self
.
assertIsNotNone
(
pkgutil
.
get_loader
(
"test.support"
))
self
.
assertIsNotNone
(
pkgutil
.
get_loader
(
"test.support"
))
self
.
assertEqual
(
len
(
w
.
warnings
),
0
)
self
.
assertEqual
(
len
(
w
.
warnings
),
0
)
def
test_get_loader_handles_missing_loader_attribute
(
self
):
global
__loader__
this_loader
=
__loader__
del
__loader__
try
:
with
check_warnings
()
as
w
:
self
.
assertIsNotNone
(
pkgutil
.
get_loader
(
__name__
))
self
.
assertEqual
(
len
(
w
.
warnings
),
0
)
finally
:
__loader__
=
this_loader
def
test_find_loader_avoids_emulation
(
self
):
with
check_warnings
()
as
w
:
self
.
assertIsNotNone
(
pkgutil
.
find_loader
(
"sys"
))
self
.
assertIsNotNone
(
pkgutil
.
find_loader
(
"os"
))
self
.
assertIsNotNone
(
pkgutil
.
find_loader
(
"test.support"
))
self
.
assertEqual
(
len
(
w
.
warnings
),
0
)
def
test_get_importer_avoids_emulation
(
self
):
def
test_get_importer_avoids_emulation
(
self
):
# We use an illegal path so *none* of the path hooks should fire
# We use an illegal path so *none* of the path hooks should fire
with
check_warnings
()
as
w
:
with
check_warnings
()
as
w
:
...
...
Misc/NEWS
Dosyayı görüntüle @
62b4b9ee
...
@@ -12,6 +12,13 @@ Core and Builtins
...
@@ -12,6 +12,13 @@ Core and Builtins
- Issue #20786: Fix signatures for dict.__delitem__ and
- Issue #20786: Fix signatures for dict.__delitem__ and
property.__delete__ builtins.
property.__delete__ builtins.
Library
-------
- Issue #20839: Don'
t
trigger
a
DeprecationWarning
in
the
still
supported
pkgutil
.
get_loader
()
API
when
__loader__
isn
't set on a module (nor
when pkgutil.find_loader() is called directly).
Build
Build
-----
-----
...
@@ -27,7 +34,7 @@ Build
...
@@ -27,7 +34,7 @@ Build
uninstalling pip (rather than failing) if the user has updated pip to a
uninstalling pip (rather than failing) if the user has updated pip to a
different version from the one bundled with ensurepip.
different version from the one bundled with ensurepip.
- Issue #20465: Update OS X and Windows installer builds to use
- Issue #20465: Update OS X and Windows installer builds to use
SQLite 3.8.3.1.
SQLite 3.8.3.1.
...
...
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