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
47dee11b
Kaydet (Commit)
47dee11b
authored
Eyl 27, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #21578: Fixed misleading error message when ImportError called with
invalid keyword args.
üst
c0b7037d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
22 deletions
+44
-22
test_exceptions.py
Lib/test/test_exceptions.py
+17
-0
NEWS
Misc/NEWS
+3
-0
exceptions.c
Objects/exceptions.c
+24
-22
No files found.
Lib/test/test_exceptions.py
Dosyayı görüntüle @
47dee11b
...
@@ -1096,6 +1096,23 @@ class ImportErrorTests(unittest.TestCase):
...
@@ -1096,6 +1096,23 @@ class ImportErrorTests(unittest.TestCase):
self
.
assertEqual
(
exc
.
name
,
'somename'
)
self
.
assertEqual
(
exc
.
name
,
'somename'
)
self
.
assertEqual
(
exc
.
path
,
'somepath'
)
self
.
assertEqual
(
exc
.
path
,
'somepath'
)
msg
=
"'invalid' is an invalid keyword argument for this function"
with
self
.
assertRaisesRegex
(
TypeError
,
msg
):
ImportError
(
'test'
,
invalid
=
'keyword'
)
with
self
.
assertRaisesRegex
(
TypeError
,
msg
):
ImportError
(
'test'
,
name
=
'name'
,
invalid
=
'keyword'
)
with
self
.
assertRaisesRegex
(
TypeError
,
msg
):
ImportError
(
'test'
,
path
=
'path'
,
invalid
=
'keyword'
)
with
self
.
assertRaisesRegex
(
TypeError
,
msg
):
ImportError
(
invalid
=
'keyword'
)
msg
=
"'invalid|another' is an invalid keyword argument for this function"
with
self
.
assertRaisesRegex
(
TypeError
,
msg
):
ImportError
(
'test'
,
invalid
=
'keyword'
,
another
=
True
)
def
test_non_str_argument
(
self
):
def
test_non_str_argument
(
self
):
# Issue #15778
# Issue #15778
with
check_warnings
((
''
,
BytesWarning
),
quiet
=
True
):
with
check_warnings
((
''
,
BytesWarning
),
quiet
=
True
):
...
...
Misc/NEWS
Dosyayı görüntüle @
47dee11b
...
@@ -10,6 +10,9 @@ Release date: TBA
...
@@ -10,6 +10,9 @@ Release date: TBA
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #21578: Fixed misleading error message when ImportError called with
invalid keyword args.
- Issue #28203: Fix incorrect type in error message from
- Issue #28203: Fix incorrect type in error message from
``complex(1.0, {2:3})``. Patch by Soumya Sharma.
``complex(1.0, {2:3})``. Patch by Soumya Sharma.
...
...
Objects/exceptions.c
Dosyayı görüntüle @
47dee11b
...
@@ -618,36 +618,38 @@ SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt,
...
@@ -618,36 +618,38 @@ SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt,
static
int
static
int
ImportError_init
(
PyImportErrorObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
ImportError_init
(
PyImportErrorObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
static
char
*
kwlist
[]
=
{
"name"
,
"path"
,
0
};
PyObject
*
empty_tuple
;
PyObject
*
msg
=
NULL
;
PyObject
*
msg
=
NULL
;
PyObject
*
name
=
NULL
;
PyObject
*
name
=
NULL
;
PyObject
*
path
=
NULL
;
PyObject
*
path
=
NULL
;
/* Macro replacement doesn't allow ## to start the first line of a macro,
if
(
BaseException_init
((
PyBaseExceptionObject
*
)
self
,
args
,
NULL
)
==
-
1
)
so we move the assignment and NULL check into the if-statement. */
return
-
1
;
#define GET_KWD(kwd) { \
kwd = PyDict_GetItemString(kwds, #kwd); \
if (kwd) { \
Py_INCREF(kwd); \
Py_XSETREF(self->kwd, kwd); \
if (PyDict_DelItemString(kwds, #kwd)) \
return -1; \
} \
}
if
(
kwds
)
{
GET_KWD
(
name
);
GET_KWD
(
path
);
}
if
(
BaseException_init
((
PyBaseExceptionObject
*
)
self
,
args
,
kwds
)
==
-
1
)
empty_tuple
=
PyTuple_New
(
0
);
if
(
!
empty_tuple
)
return
-
1
;
return
-
1
;
if
(
PyTuple_GET_SIZE
(
args
)
!=
1
)
if
(
!
PyArg_ParseTupleAndKeywords
(
empty_tuple
,
kwds
,
"|$OO:ImportError"
,
kwlist
,
return
0
;
&
name
,
&
path
))
{
if
(
!
PyArg_UnpackTuple
(
args
,
"ImportError"
,
1
,
1
,
&
msg
))
Py_DECREF
(
empty_tuple
);
return
-
1
;
return
-
1
;
}
Py_DECREF
(
empty_tuple
);
Py_INCREF
(
msg
);
if
(
name
)
{
Py_XSETREF
(
self
->
msg
,
msg
);
Py_INCREF
(
name
);
Py_XSETREF
(
self
->
name
,
name
);
}
if
(
path
)
{
Py_INCREF
(
path
);
Py_XSETREF
(
self
->
path
,
path
);
}
if
(
PyTuple_GET_SIZE
(
args
)
==
1
)
{
msg
=
PyTuple_GET_ITEM
(
args
,
0
);
Py_INCREF
(
msg
);
Py_XSETREF
(
self
->
msg
,
msg
);
}
return
0
;
return
0
;
}
}
...
...
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