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
416f12dd
Kaydet (Commit)
416f12dd
authored
Ara 15, 2011
tarafından
Meador Inge
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #13591: import_module potentially imports a module twice.
üst
061c0289
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
2 deletions
+29
-2
_bootstrap.py
Lib/importlib/_bootstrap.py
+3
-1
test_api.py
Lib/importlib/test/test_api.py
+17
-0
util.py
Lib/importlib/test/util.py
+6
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/importlib/_bootstrap.py
Dosyayı görüntüle @
416f12dd
...
...
@@ -816,7 +816,9 @@ def _gcd_import(name, package=None, level=0):
for
finder
in
meta_path
:
loader
=
finder
.
find_module
(
name
,
path
)
if
loader
is
not
None
:
loader
.
load_module
(
name
)
# The parent import may have already imported this module.
if
name
not
in
sys
.
modules
:
loader
.
load_module
(
name
)
break
else
:
raise
ImportError
(
_ERR_MSG
.
format
(
name
))
...
...
Lib/importlib/test/test_api.py
Dosyayı görüntüle @
416f12dd
...
...
@@ -67,6 +67,23 @@ class ImportModuleTests(unittest.TestCase):
importlib
.
import_module
(
'.support'
)
def
test_loaded_once
(
self
):
# Issue #13591: Modules should only be loaded once when
# initializing the parent package attempts to import the
# module currently being imported.
b_load_count
=
0
def
load_a
():
importlib
.
import_module
(
'a.b'
)
def
load_b
():
nonlocal
b_load_count
b_load_count
+=
1
code
=
{
'a'
:
load_a
,
'a.b'
:
load_b
}
modules
=
[
'a.__init__'
,
'a.b'
]
with
util
.
mock_modules
(
*
modules
,
module_code
=
code
)
as
mock
:
with
util
.
import_state
(
meta_path
=
[
mock
]):
importlib
.
import_module
(
'a.b'
)
self
.
assertEqual
(
b_load_count
,
1
)
def
test_main
():
from
test.support
import
run_unittest
run_unittest
(
ImportModuleTests
)
...
...
Lib/importlib/test/util.py
Dosyayı görüntüle @
416f12dd
...
...
@@ -84,8 +84,9 @@ class mock_modules:
"""A mock importer/loader."""
def
__init__
(
self
,
*
names
):
def
__init__
(
self
,
*
names
,
module_code
=
{}
):
self
.
modules
=
{}
self
.
module_code
=
{}
for
name
in
names
:
if
not
name
.
endswith
(
'.__init__'
):
import_name
=
name
...
...
@@ -105,6 +106,8 @@ class mock_modules:
if
import_name
!=
name
:
module
.
__path__
=
[
'<mock __path__>'
]
self
.
modules
[
import_name
]
=
module
if
import_name
in
module_code
:
self
.
module_code
[
import_name
]
=
module_code
[
import_name
]
def
__getitem__
(
self
,
name
):
return
self
.
modules
[
name
]
...
...
@@ -120,6 +123,8 @@ class mock_modules:
raise
ImportError
else
:
sys
.
modules
[
fullname
]
=
self
.
modules
[
fullname
]
if
fullname
in
self
.
module_code
:
self
.
module_code
[
fullname
]()
return
self
.
modules
[
fullname
]
def
__enter__
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
416f12dd
...
...
@@ -1868,6 +1868,9 @@ Core and Builtins
Library
-------
- Issue #13591: A bug in importlib has been fixed that caused import_module
to load a module twice.
- logging: added "handler of last resort". See http://bit.ly/last-resort-handler
- test.support: Added TestHandler and Matcher classes for better support of
...
...
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