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
b70091a8
Kaydet (Commit)
b70091a8
authored
May 16, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20014: array.array() now accepts unicode typecodes. Based on patch by
Vajrasky Kok.
üst
f40fcb33
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
3 deletions
+39
-3
test_array.py
Lib/test/test_array.py
+21
-0
NEWS
Misc/NEWS
+3
-0
arraymodule.c
Modules/arraymodule.c
+15
-3
No files found.
Lib/test/test_array.py
Dosyayı görüntüle @
b70091a8
...
...
@@ -26,7 +26,17 @@ class BadConstructorTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
array
.
array
)
self
.
assertRaises
(
TypeError
,
array
.
array
,
spam
=
42
)
self
.
assertRaises
(
TypeError
,
array
.
array
,
'xx'
)
self
.
assertRaises
(
TypeError
,
array
.
array
,
''
)
self
.
assertRaises
(
TypeError
,
array
.
array
,
1
)
self
.
assertRaises
(
ValueError
,
array
.
array
,
'x'
)
self
.
assertRaises
(
ValueError
,
array
.
array
,
'
\x80
'
)
@test_support.requires_unicode
def
test_unicode_constructor
(
self
):
self
.
assertRaises
(
TypeError
,
array
.
array
,
u'xx'
)
self
.
assertRaises
(
TypeError
,
array
.
array
,
u''
)
self
.
assertRaises
(
ValueError
,
array
.
array
,
u'x'
)
self
.
assertRaises
(
ValueError
,
array
.
array
,
u'
\x80
'
)
tests
.
append
(
BadConstructorTest
)
...
...
@@ -1039,6 +1049,17 @@ class UnsignedLongTest(UnsignedNumberTest):
minitemsize
=
4
tests
.
append
(
UnsignedLongTest
)
@test_support.requires_unicode
class
UnicodeTypecodeTest
(
unittest
.
TestCase
):
def
test_unicode_typecode
(
self
):
for
typecode
in
typecodes
:
a
=
array
.
array
(
unicode
(
typecode
))
self
.
assertEqual
(
a
.
typecode
,
typecode
)
self
.
assertIs
(
type
(
a
.
typecode
),
str
)
tests
.
append
(
UnicodeTypecodeTest
)
class
FPTest
(
NumberTest
):
example
=
[
-
42.0
,
0
,
42
,
1e5
,
-
1e10
]
smallerexample
=
[
-
42.0
,
0
,
42
,
1e5
,
-
2e10
]
...
...
Misc/NEWS
Dosyayı görüntüle @
b70091a8
...
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- Issue #20014: array.array() now accepts unicode typecodes. Based on patch by
Vajrasky Kok.
- Issue #23637: Showing a warning no longer fails with UnicodeErrror.
Formatting unicode warning in the file with the path containing non-ascii
characters no longer fails with UnicodeErrror.
...
...
Modules/arraymodule.c
Dosyayı görüntüle @
b70091a8
...
...
@@ -1928,16 +1928,28 @@ static PyBufferProcs array_as_buffer = {
static
PyObject
*
array_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
char
c
;
PyObject
*
initial
=
NULL
,
*
it
=
NULL
;
int
c
=
-
1
;
PyObject
*
initial
=
NULL
,
*
it
=
NULL
,
*
typecode
=
NULL
;
struct
arraydescr
*
descr
;
if
(
type
==
&
Arraytype
&&
!
_PyArg_NoKeywords
(
"array.array()"
,
kwds
))
return
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
c|O:array"
,
&
c
,
&
initial
))
if
(
!
PyArg_ParseTuple
(
args
,
"
O|O:array"
,
&
typecode
,
&
initial
))
return
NULL
;
if
(
PyString_Check
(
typecode
)
&&
PyString_GET_SIZE
(
typecode
)
==
1
)
c
=
(
unsigned
char
)
*
PyString_AS_STRING
(
typecode
);
else
if
(
PyUnicode_Check
(
typecode
)
&&
PyUnicode_GET_SIZE
(
typecode
)
==
1
)
c
=
*
PyUnicode_AS_UNICODE
(
typecode
);
else
{
PyErr_Format
(
PyExc_TypeError
,
"array() argument 1 or typecode must be char (string or "
"ascii-unicode with length 1), not %s"
,
Py_TYPE
(
typecode
)
->
tp_name
);
return
NULL
;
}
if
(
!
(
initial
==
NULL
||
PyList_Check
(
initial
)
||
PyString_Check
(
initial
)
||
PyTuple_Check
(
initial
)
||
(
c
==
'u'
&&
PyUnicode_Check
(
initial
))))
{
...
...
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