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
fdcdd9ed
Kaydet (Commit)
fdcdd9ed
authored
Tem 08, 2016
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #26896: Disambiguate uses of "importer" with "finder".
Thanks to Oren Milman for the patch.
üst
15552c39
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
32 additions
and
32 deletions
+32
-32
import.rst
Doc/c-api/import.rst
+4
-4
pkgutil.rst
Doc/library/pkgutil.rst
+9
-9
pkgutil.py
Lib/pkgutil.py
+11
-11
runpy.py
Lib/runpy.py
+2
-2
test_meta_path.py
Lib/test/test_importlib/import_/test_meta_path.py
+0
-1
util.py
Lib/test/test_importlib/util.py
+0
-1
test_pkgutil.py
Lib/test/test_pkgutil.py
+1
-1
ACKS
Misc/ACKS
+1
-0
import.c
Python/import.c
+4
-3
No files found.
Doc/c-api/import.rst
Dosyayı görüntüle @
fdcdd9ed
...
@@ -207,13 +207,13 @@ Importing Modules
...
@@ -207,13 +207,13 @@ Importing Modules
.. c:function:: PyObject* PyImport_GetImporter(PyObject *path)
.. c:function:: PyObject* PyImport_GetImporter(PyObject *path)
Return a
n import
er object for a :data:`sys.path`/:attr:`pkg.__path__` item
Return a
find
er object for a :data:`sys.path`/:attr:`pkg.__path__` item
*path*, possibly by fetching it from the :data:`sys.path_importer_cache`
*path*, possibly by fetching it from the :data:`sys.path_importer_cache`
dict. If it wasn't yet cached, traverse :data:`sys.path_hooks` until a hook
dict. If it wasn't yet cached, traverse :data:`sys.path_hooks` until a hook
is found that can handle the path item. Return ``None`` if no hook could;
is found that can handle the path item. Return ``None`` if no hook could;
this tells our caller
it should fall back to the built-in import mechanism.
this tells our caller
that the :term:`path based finder` could not find a
Cache the result in :data:`sys.path_importer_cache`. Return a new reference
finder for this path item. Cache the result in :data:`sys.path_importer_cache`.
to the import
er object.
Return a new reference to the find
er object.
.. c:function:: void _PyImport_Init()
.. c:function:: void _PyImport_Init()
...
...
Doc/library/pkgutil.rst
Dosyayı görüntüle @
fdcdd9ed
...
@@ -46,10 +46,10 @@ support.
...
@@ -46,10 +46,10 @@ support.
.. class:: ImpImporter(dirname=None)
.. class:: ImpImporter(dirname=None)
:pep:`302`
Import
er that wraps Python'
s
"classic"
import
algorithm
.
:pep:`302`
Find
er that wraps Python'
s
"classic"
import
algorithm
.
If
*
dirname
*
is
a
string
,
a
:
pep
:`
302
`
import
er
is
created
that
searches
that
If
*
dirname
*
is
a
string
,
a
:
pep
:`
302
`
find
er
is
created
that
searches
that
directory
.
If
*
dirname
*
is
``
None
``,
a
:
pep
:`
302
`
import
er
is
created
that
directory
.
If
*
dirname
*
is
``
None
``,
a
:
pep
:`
302
`
find
er
is
created
that
searches
the
current
:
data
:`
sys
.
path
`,
plus
any
modules
that
are
frozen
or
searches
the
current
:
data
:`
sys
.
path
`,
plus
any
modules
that
are
frozen
or
built
-
in
.
built
-
in
.
...
@@ -88,9 +88,9 @@ support.
...
@@ -88,9 +88,9 @@ support.
.. function:: get_importer(path_item)
.. function:: get_importer(path_item)
Retrieve a :pep:`302`
import
er for the given *path_item*.
Retrieve a :pep:`302`
find
er for the given *path_item*.
The returned
import
er is cached in :data:`sys.path_importer_cache` if it was
The returned
find
er is cached in :data:`sys.path_importer_cache` if it was
newly created by a path hook.
newly created by a path hook.
The cache (or part of it) can be cleared manually if a rescan of
The cache (or part of it) can be cleared manually if a rescan of
...
@@ -121,16 +121,16 @@ support.
...
@@ -121,16 +121,16 @@ support.
.. function:: iter_importers(fullname='')
.. function:: iter_importers(fullname='')
Yield :pep:`302`
import
ers for the given module name.
Yield :pep:`302`
find
ers for the given module name.
If fullname contains a '
.
', the
import
ers will be for the package
If fullname contains a '
.
', the
find
ers will be for the package
containing fullname, otherwise they will be all registered top level
containing fullname, otherwise they will be all registered top level
import
ers (i.e. those on both sys.meta_path and sys.path_hooks).
find
ers (i.e. those on both sys.meta_path and sys.path_hooks).
If the named module is in a package, that package is imported as a side
If the named module is in a package, that package is imported as a side
effect of invoking this function.
effect of invoking this function.
If no module name is specified, all top level
import
ers are produced.
If no module name is specified, all top level
find
ers are produced.
.. 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
...
...
Lib/pkgutil.py
Dosyayı görüntüle @
fdcdd9ed
...
@@ -45,7 +45,7 @@ def read_code(stream):
...
@@ -45,7 +45,7 @@ def read_code(stream):
def
walk_packages
(
path
=
None
,
prefix
=
''
,
onerror
=
None
):
def
walk_packages
(
path
=
None
,
prefix
=
''
,
onerror
=
None
):
"""Yields (module_
loa
der, name, ispkg) for all modules recursively
"""Yields (module_
fin
der, name, ispkg) for all modules recursively
on path, or, if path is None, all accessible modules.
on path, or, if path is None, all accessible modules.
'path' should be either None or a list of paths to look for
'path' should be either None or a list of paths to look for
...
@@ -102,7 +102,7 @@ def walk_packages(path=None, prefix='', onerror=None):
...
@@ -102,7 +102,7 @@ def walk_packages(path=None, prefix='', onerror=None):
def
iter_modules
(
path
=
None
,
prefix
=
''
):
def
iter_modules
(
path
=
None
,
prefix
=
''
):
"""Yields (module_
loa
der, name, ispkg) for all submodules on path,
"""Yields (module_
fin
der, name, ispkg) for all submodules on path,
or, if path is None, all top-level modules on sys.path.
or, if path is None, all top-level modules on sys.path.
'path' should be either None or a list of paths to look for
'path' should be either None or a list of paths to look for
...
@@ -184,10 +184,10 @@ def _import_imp():
...
@@ -184,10 +184,10 @@ def _import_imp():
imp
=
importlib
.
import_module
(
'imp'
)
imp
=
importlib
.
import_module
(
'imp'
)
class
ImpImporter
:
class
ImpImporter
:
"""PEP 302
Import
er that wraps Python's "classic" import algorithm
"""PEP 302
Find
er that wraps Python's "classic" import algorithm
ImpImporter(dirname) produces a PEP 302
import
er that searches that
ImpImporter(dirname) produces a PEP 302
find
er that searches that
directory. ImpImporter(None) produces a PEP 302
import
er that searches
directory. ImpImporter(None) produces a PEP 302
find
er that searches
the current sys.path, plus any modules that are frozen or built-in.
the current sys.path, plus any modules that are frozen or built-in.
Note that ImpImporter does not currently support being used by placement
Note that ImpImporter does not currently support being used by placement
...
@@ -395,9 +395,9 @@ except ImportError:
...
@@ -395,9 +395,9 @@ except ImportError:
def
get_importer
(
path_item
):
def
get_importer
(
path_item
):
"""Retrieve a PEP 302
import
er for the given path item
"""Retrieve a PEP 302
find
er for the given path item
The returned
import
er is cached in sys.path_importer_cache
The returned
find
er is cached in sys.path_importer_cache
if it was newly created by a path hook.
if it was newly created by a path hook.
The cache (or part of it) can be cleared manually if a
The cache (or part of it) can be cleared manually if a
...
@@ -419,16 +419,16 @@ def get_importer(path_item):
...
@@ -419,16 +419,16 @@ def get_importer(path_item):
def
iter_importers
(
fullname
=
""
):
def
iter_importers
(
fullname
=
""
):
"""Yield PEP 302
import
ers for the given module name
"""Yield PEP 302
find
ers for the given module name
If fullname contains a '.', the
import
ers will be for the package
If fullname contains a '.', the
find
ers will be for the package
containing fullname, otherwise they will be all registered top level
containing fullname, otherwise they will be all registered top level
import
ers (i.e. those on both sys.meta_path and sys.path_hooks).
find
ers (i.e. those on both sys.meta_path and sys.path_hooks).
If the named module is in a package, that package is imported as a side
If the named module is in a package, that package is imported as a side
effect of invoking this function.
effect of invoking this function.
If no module name is specified, all top level
import
ers are produced.
If no module name is specified, all top level
find
ers are produced.
"""
"""
if
fullname
.
startswith
(
'.'
):
if
fullname
.
startswith
(
'.'
):
msg
=
"Relative module name {!r} not supported"
.
format
(
fullname
)
msg
=
"Relative module name {!r} not supported"
.
format
(
fullname
)
...
...
Lib/runpy.py
Dosyayı görüntüle @
fdcdd9ed
...
@@ -98,7 +98,7 @@ def _run_module_code(code, init_globals=None,
...
@@ -98,7 +98,7 @@ def _run_module_code(code, init_globals=None,
# may be cleared when the temporary module goes away
# may be cleared when the temporary module goes away
return
mod_globals
.
copy
()
return
mod_globals
.
copy
()
# Helper to get the
loader, code and filenam
e for a module
# Helper to get the
full name, spec and cod
e for a module
def
_get_module_details
(
mod_name
,
error
=
ImportError
):
def
_get_module_details
(
mod_name
,
error
=
ImportError
):
if
mod_name
.
startswith
(
"."
):
if
mod_name
.
startswith
(
"."
):
raise
error
(
"Relative module names not supported"
)
raise
error
(
"Relative module names not supported"
)
...
@@ -253,7 +253,7 @@ def run_path(path_name, init_globals=None, run_name=None):
...
@@ -253,7 +253,7 @@ def run_path(path_name, init_globals=None, run_name=None):
return
_run_module_code
(
code
,
init_globals
,
run_name
,
return
_run_module_code
(
code
,
init_globals
,
run_name
,
pkg_name
=
pkg_name
,
script_name
=
fname
)
pkg_name
=
pkg_name
,
script_name
=
fname
)
else
:
else
:
#
Import
er is defined for path, so add it to
#
Find
er is defined for path, so add it to
# the start of sys.path
# the start of sys.path
sys
.
path
.
insert
(
0
,
path_name
)
sys
.
path
.
insert
(
0
,
path_name
)
try
:
try
:
...
...
Lib/test/test_importlib/import_/test_meta_path.py
Dosyayı görüntüle @
fdcdd9ed
...
@@ -76,7 +76,6 @@ class CallSignature:
...
@@ -76,7 +76,6 @@ class CallSignature:
self
.
__import__
(
mod_name
)
self
.
__import__
(
mod_name
)
assert
len
(
log
)
==
1
assert
len
(
log
)
==
1
args
=
log
[
0
][
0
]
args
=
log
[
0
][
0
]
kwargs
=
log
[
0
][
1
]
# Assuming all arguments are positional.
# Assuming all arguments are positional.
self
.
assertEqual
(
args
[
0
],
mod_name
)
self
.
assertEqual
(
args
[
0
],
mod_name
)
self
.
assertIsNone
(
args
[
1
])
self
.
assertIsNone
(
args
[
1
])
...
...
Lib/test/test_importlib/util.py
Dosyayı görüntüle @
fdcdd9ed
...
@@ -266,7 +266,6 @@ class mock_spec(_ImporterMock):
...
@@ -266,7 +266,6 @@ class mock_spec(_ImporterMock):
module
=
self
.
modules
[
fullname
]
module
=
self
.
modules
[
fullname
]
except
KeyError
:
except
KeyError
:
return
None
return
None
is_package
=
hasattr
(
module
,
'__path__'
)
spec
=
util
.
spec_from_file_location
(
spec
=
util
.
spec_from_file_location
(
fullname
,
module
.
__file__
,
loader
=
self
,
fullname
,
module
.
__file__
,
loader
=
self
,
submodule_search_locations
=
getattr
(
module
,
'__path__'
,
None
))
submodule_search_locations
=
getattr
(
module
,
'__path__'
,
None
))
...
...
Lib/test/test_pkgutil.py
Dosyayı görüntüle @
fdcdd9ed
...
@@ -205,7 +205,7 @@ class PkgutilPEP302Tests(unittest.TestCase):
...
@@ -205,7 +205,7 @@ class PkgutilPEP302Tests(unittest.TestCase):
del
sys
.
meta_path
[
0
]
del
sys
.
meta_path
[
0
]
def
test_getdata_pep302
(
self
):
def
test_getdata_pep302
(
self
):
# Use a dummy
import
er/loader
# Use a dummy
find
er/loader
self
.
assertEqual
(
pkgutil
.
get_data
(
'foo'
,
'dummy'
),
"Hello, world!"
)
self
.
assertEqual
(
pkgutil
.
get_data
(
'foo'
,
'dummy'
),
"Hello, world!"
)
del
sys
.
modules
[
'foo'
]
del
sys
.
modules
[
'foo'
]
...
...
Misc/ACKS
Dosyayı görüntüle @
fdcdd9ed
...
@@ -998,6 +998,7 @@ Damien Miller
...
@@ -998,6 +998,7 @@ Damien Miller
Jason V. Miller
Jason V. Miller
Jay T. Miller
Jay T. Miller
Katie Miller
Katie Miller
Oren Milman
Roman Milner
Roman Milner
Julien Miotte
Julien Miotte
Andrii V. Mishkovskyi
Andrii V. Mishkovskyi
...
...
Python/import.c
Dosyayı görüntüle @
fdcdd9ed
...
@@ -950,12 +950,13 @@ is_builtin(PyObject *name)
...
@@ -950,12 +950,13 @@ is_builtin(PyObject *name)
}
}
/* Return a
n import
er object for a sys.path/pkg.__path__ item 'p',
/* Return a
find
er object for a sys.path/pkg.__path__ item 'p',
possibly by fetching it from the path_importer_cache dict. If it
possibly by fetching it from the path_importer_cache dict. If it
wasn't yet cached, traverse path_hooks until a hook is found
wasn't yet cached, traverse path_hooks until a hook is found
that can handle the path item. Return None if no hook could;
that can handle the path item. Return None if no hook could;
this tells our caller it should fall back to the builtin
this tells our caller that the path based finder could not find
import mechanism. Cache the result in path_importer_cache.
a finder for this path item. Cache the result in
path_importer_cache.
Returns a borrowed reference. */
Returns a borrowed reference. */
static
PyObject
*
static
PyObject
*
...
...
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