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
e18ef194
Kaydet (Commit)
e18ef194
authored
Ock 20, 2009
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
allow unicode keyword arguments for the ** syntax #4978
üst
196a0f7a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
12 deletions
+55
-12
test_extcall.py
Lib/test/test_extcall.py
+20
-0
NEWS
Misc/NEWS
+2
-0
ceval.c
Python/ceval.c
+33
-12
No files found.
Lib/test/test_extcall.py
Dosyayı görüntüle @
e18ef194
# -*- coding: utf-8 -*-
"""Doctest for method/function calls.
We're going the use these types for extra testing
...
...
@@ -252,11 +253,30 @@ TypeError if te dictionary is not empty
"""
import
unittest
from
test
import
test_support
class
UnicodeKeywordArgsTest
(
unittest
.
TestCase
):
def
test_unicode_keywords
(
self
):
def
f
(
a
):
return
a
self
.
assertEqual
(
f
(
**
{
u'a'
:
4
}),
4
)
self
.
assertRaises
(
TypeError
,
f
,
**
{
u'stören'
:
4
})
self
.
assertRaises
(
TypeError
,
f
,
**
{
u'someLongString'
:
2
})
try
:
f
(
a
=
4
,
**
{
u'a'
:
4
})
except
TypeError
:
pass
else
:
self
.
fail
(
"duplicate arguments didn't raise"
)
def
test_main
():
from
test
import
test_extcall
# self import
test_support
.
run_doctest
(
test_extcall
,
True
)
test_support
.
run_unittest
(
UnicodeKeywordArgsTest
)
if
__name__
==
'__main__'
:
test_main
()
Misc/NEWS
Dosyayı görüntüle @
e18ef194
...
...
@@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 1
Core and Builtins
-----------------
- Issue #4978: Passing keyword arguments as unicode strings is now allowed.
- os.ftruncate raises OSErrors instead of IOErrors for consistency with other os
functions.
...
...
Python/ceval.c
Dosyayı görüntüle @
e18ef194
...
...
@@ -127,6 +127,7 @@ static void reset_exc_info(PyThreadState *);
static
void
format_exc_check_arg
(
PyObject
*
,
char
*
,
PyObject
*
);
static
PyObject
*
string_concatenate
(
PyObject
*
,
PyObject
*
,
PyFrameObject
*
,
unsigned
char
*
);
static
PyObject
*
kwd_as_string
(
PyObject
*
);
#define NAME_ERROR_MSG \
"name '%.200s' is not defined"
...
...
@@ -2932,7 +2933,8 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
PyObject
*
keyword
=
kws
[
2
*
i
];
PyObject
*
value
=
kws
[
2
*
i
+
1
];
int
j
;
if
(
keyword
==
NULL
||
!
PyString_Check
(
keyword
))
{
if
(
keyword
==
NULL
||
!
(
PyString_Check
(
keyword
)
||
PyUnicode_Check
(
keyword
)))
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s() keywords must be strings"
,
PyString_AsString
(
co
->
co_name
));
...
...
@@ -2961,11 +2963,15 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
goto
fail
;
if
(
j
>=
co
->
co_argcount
)
{
if
(
kwdict
==
NULL
)
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s() got an unexpected "
"keyword argument '%.400s'"
,
PyString_AsString
(
co
->
co_name
),
PyString_AsString
(
keyword
));
PyObject
*
kwd_str
=
kwd_as_string
(
keyword
);
if
(
kwd_str
)
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s() got an unexpected "
"keyword argument '%.400s'"
,
PyString_AsString
(
co
->
co_name
),
PyString_AsString
(
kwd_str
));
Py_DECREF
(
kwd_str
);
}
goto
fail
;
}
PyDict_SetItem
(
kwdict
,
keyword
,
value
);
...
...
@@ -2973,12 +2979,16 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
}
kw_found:
if
(
GETLOCAL
(
j
)
!=
NULL
)
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s() got multiple "
"values for keyword "
"argument '%.400s'"
,
PyString_AsString
(
co
->
co_name
),
PyString_AsString
(
keyword
));
PyObject
*
kwd_str
=
kwd_as_string
(
keyword
);
if
(
kwd_str
)
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s() got multiple "
"values for keyword "
"argument '%.400s'"
,
PyString_AsString
(
co
->
co_name
),
PyString_AsString
(
kwd_str
));
Py_DECREF
(
kwd_str
);
}
goto
fail
;
}
Py_INCREF
(
value
);
...
...
@@ -3105,6 +3115,17 @@ fail: /* Jump here from prelude on failure */
}
static
PyObject
*
kwd_as_string
(
PyObject
*
kwd
)
{
if
(
PyString_Check
(
kwd
))
{
Py_INCREF
(
kwd
);
return
kwd
;
}
else
return
_PyUnicode_AsDefaultEncodedString
(
kwd
,
"replace"
);
}
/* Implementation notes for set_exc_info() and reset_exc_info():
- Below, 'exc_ZZZ' stands for 'exc_type', 'exc_value' and
...
...
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