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
d8b291a7
Unverified
Kaydet (Commit)
d8b291a7
authored
Mar 24, 2018
tarafından
Xiang Zhang
Kaydeden (comit)
GitHub
Mar 24, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-32932: More revealing error message when non-str objects in __all__ (GH-5848)
üst
5cbb8410
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
1 deletion
+49
-1
__init__.py
Lib/test/test_import/__init__.py
+21
-0
2018-02-24-21-51-42.bpo-32932.2cz31L.rst
...ore and Builtins/2018-02-24-21-51-42.bpo-32932.2cz31L.rst
+1
-0
ceval.c
Python/ceval.c
+27
-1
No files found.
Lib/test/test_import/__init__.py
Dosyayı görüntüle @
d8b291a7
...
@@ -111,6 +111,27 @@ class ImportTests(unittest.TestCase):
...
@@ -111,6 +111,27 @@ class ImportTests(unittest.TestCase):
self
.
assertIn
(
cm
.
exception
.
name
,
{
'posixpath'
,
'ntpath'
})
self
.
assertIn
(
cm
.
exception
.
name
,
{
'posixpath'
,
'ntpath'
})
self
.
assertIsNotNone
(
cm
.
exception
)
self
.
assertIsNotNone
(
cm
.
exception
)
def
test_from_import_star_invalid_type
(
self
):
import
re
with
_ready_to_import
()
as
(
name
,
path
):
with
open
(
path
,
'w'
)
as
f
:
f
.
write
(
"__all__ = [b'invalid_type']"
)
globals
=
{}
with
self
.
assertRaisesRegex
(
TypeError
,
f
"{re.escape(name)}
\
.__all__ must be str"
):
exec
(
f
"from {name} import *"
,
globals
)
self
.
assertNotIn
(
b
"invalid_type"
,
globals
)
with
_ready_to_import
()
as
(
name
,
path
):
with
open
(
path
,
'w'
)
as
f
:
f
.
write
(
"globals()[b'invalid_type'] = object()"
)
globals
=
{}
with
self
.
assertRaisesRegex
(
TypeError
,
f
"{re.escape(name)}
\
.__dict__ must be str"
):
exec
(
f
"from {name} import *"
,
globals
)
self
.
assertNotIn
(
b
"invalid_type"
,
globals
)
def
test_case_sensitivity
(
self
):
def
test_case_sensitivity
(
self
):
# Brief digression to test that import is case-sensitive: if we got
# Brief digression to test that import is case-sensitive: if we got
# this far, we know for sure that "random" exists.
# this far, we know for sure that "random" exists.
...
...
Misc/NEWS.d/next/Core and Builtins/2018-02-24-21-51-42.bpo-32932.2cz31L.rst
0 → 100644
Dosyayı görüntüle @
d8b291a7
Make error message more revealing when there are non-str objects in ``__all__``.
Python/ceval.c
Dosyayı görüntüle @
d8b291a7
...
@@ -4837,6 +4837,7 @@ import_all_from(PyObject *locals, PyObject *v)
...
@@ -4837,6 +4837,7 @@ import_all_from(PyObject *locals, PyObject *v)
{
{
_Py_IDENTIFIER
(
__all__
);
_Py_IDENTIFIER
(
__all__
);
_Py_IDENTIFIER
(
__dict__
);
_Py_IDENTIFIER
(
__dict__
);
_Py_IDENTIFIER
(
__name__
);
PyObject
*
all
,
*
dict
,
*
name
,
*
value
;
PyObject
*
all
,
*
dict
,
*
name
,
*
value
;
int
skip_leading_underscores
=
0
;
int
skip_leading_underscores
=
0
;
int
pos
,
err
;
int
pos
,
err
;
...
@@ -4869,7 +4870,32 @@ import_all_from(PyObject *locals, PyObject *v)
...
@@ -4869,7 +4870,32 @@ import_all_from(PyObject *locals, PyObject *v)
PyErr_Clear
();
PyErr_Clear
();
break
;
break
;
}
}
if
(
skip_leading_underscores
&&
PyUnicode_Check
(
name
))
{
if
(
!
PyUnicode_Check
(
name
))
{
PyObject
*
modname
=
_PyObject_GetAttrId
(
v
,
&
PyId___name__
);
if
(
modname
==
NULL
)
{
Py_DECREF
(
name
);
err
=
-
1
;
break
;
}
if
(
!
PyUnicode_Check
(
modname
))
{
PyErr_Format
(
PyExc_TypeError
,
"module __name__ must be a string, not %.100s"
,
Py_TYPE
(
modname
)
->
tp_name
);
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"%s in %U.%s must be str, not %.100s"
,
skip_leading_underscores
?
"Key"
:
"Item"
,
modname
,
skip_leading_underscores
?
"__dict__"
:
"__all__"
,
Py_TYPE
(
name
)
->
tp_name
);
}
Py_DECREF
(
modname
);
Py_DECREF
(
name
);
err
=
-
1
;
break
;
}
if
(
skip_leading_underscores
)
{
if
(
PyUnicode_READY
(
name
)
==
-
1
)
{
if
(
PyUnicode_READY
(
name
)
==
-
1
)
{
Py_DECREF
(
name
);
Py_DECREF
(
name
);
err
=
-
1
;
err
=
-
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