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
7b9ff0e6
Kaydet (Commit)
7b9ff0e6
authored
Nis 24, 2014
tarafından
Ethan Furman
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue8297: module attribute lookup failures now include module name in error message.
üst
7101cb07
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
9 deletions
+52
-9
test_doctest.py
Lib/test/test_doctest.py
+2
-2
test_module.py
Lib/test/test_module.py
+16
-0
test_loader.py
Lib/unittest/test/test_loader.py
+5
-5
NEWS
Misc/NEWS
+3
-0
moduleobject.c
Objects/moduleobject.c
+26
-2
No files found.
Lib/test/test_doctest.py
Dosyayı görüntüle @
7b9ff0e6
...
...
@@ -2171,7 +2171,7 @@ def test_DocTestSuite():
>>> test.test_doctest.sillySetup
Traceback (most recent call last):
...
AttributeError:
'module' object
has no attribute 'sillySetup'
AttributeError:
module 'test.test_doctest'
has no attribute 'sillySetup'
The setUp and tearDown funtions are passed test objects. Here
we'll use the setUp function to supply the missing variable y:
...
...
@@ -2317,7 +2317,7 @@ def test_DocFileSuite():
>>> test.test_doctest.sillySetup
Traceback (most recent call last):
...
AttributeError:
'module' object
has no attribute 'sillySetup'
AttributeError:
module 'test.test_doctest'
has no attribute 'sillySetup'
The setUp and tearDown funtions are passed test objects.
Here, we'll use a setUp function to set the favorite color in
...
...
Lib/test/test_module.py
Dosyayı görüntüle @
7b9ff0e6
...
...
@@ -30,6 +30,22 @@ class ModuleTests(unittest.TestCase):
pass
self
.
assertEqual
(
foo
.
__doc__
,
ModuleType
.
__doc__
)
def
test_unintialized_missing_getattr
(
self
):
# Issue 8297
# test the text in the AttributeError of an uninitialized module
foo
=
ModuleType
.
__new__
(
ModuleType
)
self
.
assertRaisesRegex
(
AttributeError
,
"module has no attribute 'not_here'"
,
getattr
,
foo
,
"not_here"
)
def
test_missing_getattr
(
self
):
# Issue 8297
# test the text in the AttributeError
foo
=
ModuleType
(
"foo"
)
self
.
assertRaisesRegex
(
AttributeError
,
"module 'foo' has no attribute 'not_here'"
,
getattr
,
foo
,
"not_here"
)
def
test_no_docstring
(
self
):
# Regularly initialized module, no docstring
foo
=
ModuleType
(
"foo"
)
...
...
Lib/unittest/test/test_loader.py
Dosyayı görüntüle @
7b9ff0e6
...
...
@@ -255,7 +255,7 @@ class Test_TestLoader(unittest.TestCase):
try
:
loader
.
loadTestsFromName
(
'unittest.sdasfasfasdf'
)
except
AttributeError
as
e
:
self
.
assertEqual
(
str
(
e
),
"
'module' object
has no attribute 'sdasfasfasdf'"
)
self
.
assertEqual
(
str
(
e
),
"
module 'unittest'
has no attribute 'sdasfasfasdf'"
)
else
:
self
.
fail
(
"TestLoader.loadTestsFromName failed to raise AttributeError"
)
...
...
@@ -272,7 +272,7 @@ class Test_TestLoader(unittest.TestCase):
try
:
loader
.
loadTestsFromName
(
'sdasfasfasdf'
,
unittest
)
except
AttributeError
as
e
:
self
.
assertEqual
(
str
(
e
),
"
'module' object
has no attribute 'sdasfasfasdf'"
)
self
.
assertEqual
(
str
(
e
),
"
module 'unittest'
has no attribute 'sdasfasfasdf'"
)
else
:
self
.
fail
(
"TestLoader.loadTestsFromName failed to raise AttributeError"
)
...
...
@@ -635,7 +635,7 @@ class Test_TestLoader(unittest.TestCase):
try
:
loader
.
loadTestsFromNames
([
'unittest.sdasfasfasdf'
,
'unittest'
])
except
AttributeError
as
e
:
self
.
assertEqual
(
str
(
e
),
"
'module' object
has no attribute 'sdasfasfasdf'"
)
self
.
assertEqual
(
str
(
e
),
"
module 'unittest'
has no attribute 'sdasfasfasdf'"
)
else
:
self
.
fail
(
"TestLoader.loadTestsFromNames failed to raise AttributeError"
)
...
...
@@ -654,7 +654,7 @@ class Test_TestLoader(unittest.TestCase):
try
:
loader
.
loadTestsFromNames
([
'sdasfasfasdf'
],
unittest
)
except
AttributeError
as
e
:
self
.
assertEqual
(
str
(
e
),
"
'module' object
has no attribute 'sdasfasfasdf'"
)
self
.
assertEqual
(
str
(
e
),
"
module 'unittest'
has no attribute 'sdasfasfasdf'"
)
else
:
self
.
fail
(
"TestLoader.loadTestsFromName failed to raise AttributeError"
)
...
...
@@ -673,7 +673,7 @@ class Test_TestLoader(unittest.TestCase):
try
:
loader
.
loadTestsFromNames
([
'TestCase'
,
'sdasfasfasdf'
],
unittest
)
except
AttributeError
as
e
:
self
.
assertEqual
(
str
(
e
),
"
'module' object
has no attribute 'sdasfasfasdf'"
)
self
.
assertEqual
(
str
(
e
),
"
module 'unittest'
has no attribute 'sdasfasfasdf'"
)
else
:
self
.
fail
(
"TestLoader.loadTestsFromName failed to raise AttributeError"
)
...
...
Misc/NEWS
Dosyayı görüntüle @
7b9ff0e6
...
...
@@ -36,6 +36,9 @@ Core and Builtins
- Issue #20637: Key-sharing now also works for instance dictionaries of
subclasses. Patch by Peter Ingebretson.
- Issue #8297: Attributes missing from modules now include the module name
in the error text. Original patch by ysj.ray.
- Issue #19995: %c, %o, %x, and %X now raise TypeError on non-integer input.
- Issue #12546: Allow \x00 to be used as a fill character when using str, int,
...
...
Objects/moduleobject.c
Dosyayı görüntüle @
7b9ff0e6
...
...
@@ -411,6 +411,31 @@ module_repr(PyModuleObject *m)
return
PyObject_CallMethod
(
interp
->
importlib
,
"_module_repr"
,
"O"
,
m
);
}
static
PyObject
*
module_getattr
(
PyObject
*
m
,
PyObject
*
name
)
{
PyModuleObject
*
module
;
PyObject
*
attr
,
*
mod_name
;
attr
=
PyObject_GenericGetAttr
(
m
,
name
);
if
(
attr
!=
NULL
)
return
attr
;
PyErr_Clear
();
module
=
(
PyModuleObject
*
)
m
;
if
(
module
->
md_dict
!=
NULL
)
{
mod_name
=
PyDict_GetItemString
(
module
->
md_dict
,
"__name__"
);
if
(
mod_name
!=
NULL
)
{
PyErr_Format
(
PyExc_AttributeError
,
"module '%U' has no attribute '%U'"
,
mod_name
,
name
);
return
NULL
;
}
else
if
(
PyErr_Occurred
())
PyErr_Clear
();
}
PyErr_Format
(
PyExc_AttributeError
,
"module has no attribute '%U'"
,
name
);
return
NULL
;
}
static
int
module_traverse
(
PyModuleObject
*
m
,
visitproc
visit
,
void
*
arg
)
{
...
...
@@ -464,7 +489,6 @@ static PyMethodDef module_methods[] = {
{
0
}
};
PyDoc_STRVAR
(
module_doc
,
"module(name[, doc])
\n
\
\n
\
...
...
@@ -488,7 +512,7 @@ PyTypeObject PyModule_Type = {
0
,
/* tp_hash */
0
,
/* tp_call */
0
,
/* tp_str */
PyObject_GenericGetAttr
,
/* tp_getattro */
module_getattr
,
/* tp_getattro */
PyObject_GenericSetAttr
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
|
...
...
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