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
1bc15643
Kaydet (Commit)
1bc15643
authored
Şub 22, 2017
tarafından
Matthias Bussonnier
Kaydeden (comit)
Barry Warsaw
Şub 22, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-29546: Improve from-import error message with location (#103)
bpo-29546: Improve from-import error message with location
üst
d37c068e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
5 deletions
+39
-5
3.7.rst
Doc/whatsnew/3.7.rst
+3
-0
__init__.py
Lib/test/test_import/__init__.py
+13
-1
NEWS
Misc/NEWS
+2
-0
ceval.c
Python/ceval.c
+21
-4
No files found.
Doc/whatsnew/3.7.rst
Dosyayı görüntüle @
1bc15643
...
...
@@ -83,6 +83,9 @@ Other Language Changes
whitespace, not only spaces.
(Contributed by Robert Xiao in :issue:`28927`.)
* :exc:`ImportError` now displays module name and module ``__file__`` path when
``from ... import ...`` fails. :issue:`29546`.
New Modules
===========
...
...
Lib/test/test_import/__init__.py
Dosyayı görüntüle @
1bc15643
...
...
@@ -85,6 +85,15 @@ class ImportTests(unittest.TestCase):
from
os
import
i_dont_exist
self
.
assertEqual
(
cm
.
exception
.
name
,
'os'
)
self
.
assertEqual
(
cm
.
exception
.
path
,
os
.
__file__
)
self
.
assertRegex
(
str
(
cm
.
exception
),
"cannot import name 'i_dont_exist' from 'os'
\
(.*/Lib/os.py
\
)"
)
def
test_from_import_missing_attr_has_name_and_so_path
(
self
):
import
_opcode
with
self
.
assertRaises
(
ImportError
)
as
cm
:
from
_opcode
import
i_dont_exist
self
.
assertEqual
(
cm
.
exception
.
name
,
'_opcode'
)
self
.
assertEqual
(
cm
.
exception
.
path
,
_opcode
.
__file__
)
self
.
assertRegex
(
str
(
cm
.
exception
),
"cannot import name 'i_dont_exist' from '_opcode'
\
(.*
\
.(so|dll)
\
)"
)
def
test_from_import_missing_attr_has_name
(
self
):
with
self
.
assertRaises
(
ImportError
)
as
cm
:
...
...
@@ -365,9 +374,12 @@ class ImportTests(unittest.TestCase):
module_name
=
'test_from_import_AttributeError'
self
.
addCleanup
(
unload
,
module_name
)
sys
.
modules
[
module_name
]
=
AlwaysAttributeError
()
with
self
.
assertRaises
(
ImportError
):
with
self
.
assertRaises
(
ImportError
)
as
cm
:
from
test_from_import_AttributeError
import
does_not_exist
self
.
assertEqual
(
str
(
cm
.
exception
),
"cannot import name 'does_not_exist' from '<unknown module name>' (unknown location)"
)
@skip_if_dont_write_bytecode
class
FilePermissionTests
(
unittest
.
TestCase
):
...
...
Misc/NEWS
Dosyayı görüntüle @
1bc15643
...
...
@@ -24,6 +24,8 @@ Core and Builtins
- bpo-29546: Set the '
path
' and '
name
' attribute on ImportError for ``from ... import ...``.
- bpo-29546: Improve from-import error message with location
- 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 @
1bc15643
...
...
@@ -4995,7 +4995,7 @@ import_from(PyObject *v, PyObject *name)
{
PyObject
*
x
;
_Py_IDENTIFIER
(
__name__
);
PyObject
*
fullmodname
,
*
pkgname
,
*
pkgpath
;
PyObject
*
fullmodname
,
*
pkgname
,
*
pkgpath
,
*
pkgname_or_unknown
;
x
=
PyObject_GetAttr
(
v
,
name
);
if
(
x
!=
NULL
||
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
...
...
@@ -5009,7 +5009,6 @@ import_from(PyObject *v, PyObject *name)
goto
error
;
}
fullmodname
=
PyUnicode_FromFormat
(
"%U.%U"
,
pkgname
,
name
);
Py_DECREF
(
pkgname
);
if
(
fullmodname
==
NULL
)
{
return
NULL
;
}
...
...
@@ -5018,18 +5017,36 @@ import_from(PyObject *v, PyObject *name)
if
(
x
==
NULL
)
{
goto
error
;
}
Py_DECREF
(
pkgname
);
Py_INCREF
(
x
);
return
x
;
error
:
pkgpath
=
PyModule_GetFilenameObject
(
v
);
if
(
pkgname
==
NULL
)
{
pkgname_or_unknown
=
PyUnicode_FromString
(
"<unknown module name>"
);
if
(
pkgname_or_unknown
==
NULL
)
{
Py_XDECREF
(
pkgpath
);
return
NULL
;
}
}
else
{
pkgname_or_unknown
=
pkgname
;
}
if
(
pkgpath
==
NULL
||
!
PyUnicode_Check
(
pkgpath
))
{
PyErr_Clear
();
PyErr_SetImportError
(
PyUnicode_FromFormat
(
"cannot import name %R"
,
name
),
pkgname
,
NULL
);
PyErr_SetImportError
(
PyUnicode_FromFormat
(
"cannot import name %R from %R (unknown location)"
,
name
,
pkgname_or_unknown
),
pkgname
,
NULL
);
}
else
{
PyErr_SetImportError
(
PyUnicode_FromFormat
(
"cannot import name %R"
,
name
),
pkgname
,
pkgpath
);
PyErr_SetImportError
(
PyUnicode_FromFormat
(
"cannot import name %R from %R (%S)"
,
name
,
pkgname_or_unknown
,
pkgpath
),
pkgname
,
pkgpath
);
}
Py_XDECREF
(
pkgname_or_unknown
);
Py_XDECREF
(
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