Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b70091a8
Commit
b70091a8
authored
May 16, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20014: array.array() now accepts unicode typecodes. Based on patch by
Vajrasky Kok.
parent
f40fcb33
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
3 deletions
+39
-3
Lib/test/test_array.py
Lib/test/test_array.py
+21
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/arraymodule.c
Modules/arraymodule.c
+15
-3
No files found.
Lib/test/test_array.py
View file @
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
View file @
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
View file @
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