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
bc4bed44
Kaydet (Commit)
bc4bed44
authored
Şub 15, 2017
tarafından
Matthias Bussonnier
Kaydeden (comit)
Brett Cannon
Şub 15, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-29546: Set 'path' on ImportError for ``from ... import ...`` (GH-91)
üst
5ec08cea
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
2 deletions
+31
-2
__init__.py
Lib/test/test_import/__init__.py
+19
-0
NEWS
Misc/NEWS
+2
-0
ceval.c
Python/ceval.c
+10
-2
No files found.
Lib/test/test_import/__init__.py
Dosyayı görüntüle @
bc4bed44
...
...
@@ -80,6 +80,25 @@ class ImportTests(unittest.TestCase):
with
self
.
assertRaises
(
ImportError
):
from
importlib
import
something_that_should_not_exist_anywhere
def
test_from_import_missing_attr_has_name_and_path
(
self
):
with
self
.
assertRaises
(
ImportError
)
as
cm
:
from
os
import
i_dont_exist
self
.
assertEqual
(
cm
.
exception
.
name
,
'os'
)
self
.
assertEqual
(
cm
.
exception
.
path
,
os
.
__file__
)
def
test_from_import_missing_attr_has_name
(
self
):
with
self
.
assertRaises
(
ImportError
)
as
cm
:
# _warning has no path as it's a built-in module.
from
_warning
import
i_dont_exist
self
.
assertEqual
(
cm
.
exception
.
name
,
'_warning'
)
self
.
assertIsNone
(
cm
.
exception
.
path
)
def
test_from_import_missing_attr_path_is_canonical
(
self
):
with
self
.
assertRaises
(
ImportError
)
as
cm
:
from
os.path
import
i_dont_exist
self
.
assertIn
(
cm
.
exception
.
name
,
{
'posixpath'
,
'ntpath'
})
self
.
assertIsNotNone
(
cm
.
exception
)
def
test_case_sensitivity
(
self
):
# Brief digression to test that import is case-sensitive: if we got
# this far, we know for sure that "random" exists.
...
...
Misc/NEWS
Dosyayı görüntüle @
bc4bed44
...
...
@@ -12,6 +12,8 @@ Core and Builtins
- bpo-29438: Fixed use-after-free problem in key sharing dict.
- bpo-29546: Set the '
path
' and '
name
' attribute on ImportError for ``from ... import ...``.
- Issue #29319: Prevent RunMainFromImporter overwriting sys.path[0].
- Issue #29337: Fixed possible BytesWarning when compare the code objects.
...
...
Python/ceval.c
Dosyayı görüntüle @
bc4bed44
...
...
@@ -4995,7 +4995,7 @@ import_from(PyObject *v, PyObject *name)
{
PyObject
*
x
;
_Py_IDENTIFIER
(
__name__
);
PyObject
*
fullmodname
,
*
pkgname
;
PyObject
*
fullmodname
,
*
pkgname
,
*
pkgpath
;
x
=
PyObject_GetAttr
(
v
,
name
);
if
(
x
!=
NULL
||
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
...
...
@@ -5021,7 +5021,15 @@ import_from(PyObject *v, PyObject *name)
Py_INCREF
(
x
);
return
x
;
error
:
PyErr_Format
(
PyExc_ImportError
,
"cannot import name %R"
,
name
);
pkgpath
=
PyModule_GetFilenameObject
(
v
);
if
(
pkgpath
==
NULL
||
!
PyUnicode_Check
(
pkgpath
))
{
PyErr_Clear
();
PyErr_SetImportError
(
PyUnicode_FromFormat
(
"cannot import name %R"
,
name
),
pkgname
,
NULL
);
}
else
{
PyErr_SetImportError
(
PyUnicode_FromFormat
(
"cannot import name %R"
,
name
),
pkgname
,
pkgpath
);
}
return
NULL
;
}
...
...
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