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
9730e335
Kaydet (Commit)
9730e335
authored
Kas 30, 2013
tarafından
Alexandre Vassalotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #3693: Fix array obscure error message when given a str.
üst
ed7dc14d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
18 deletions
+43
-18
test_array.py
Lib/test/test_array.py
+12
-0
NEWS
Misc/NEWS
+4
-0
arraymodule.c
Modules/arraymodule.c
+27
-18
No files found.
Lib/test/test_array.py
Dosyayı görüntüle @
9730e335
...
...
@@ -1027,6 +1027,18 @@ class BaseTest:
basesize
=
support
.
calcvobjsize
(
'Pn2Pi'
)
support
.
check_sizeof
(
self
,
a
,
basesize
)
def
test_initialize_with_unicode
(
self
):
if
self
.
typecode
!=
'u'
:
with
self
.
assertRaises
(
TypeError
)
as
cm
:
a
=
array
.
array
(
self
.
typecode
,
'foo'
)
self
.
assertIn
(
"cannot use a str"
,
str
(
cm
.
exception
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
a
=
array
.
array
(
self
.
typecode
,
array
.
array
(
'u'
,
'foo'
))
self
.
assertIn
(
"cannot use a unicode array"
,
str
(
cm
.
exception
))
else
:
a
=
array
.
array
(
self
.
typecode
,
"foo"
)
a
=
array
.
array
(
self
.
typecode
,
array
.
array
(
'u'
,
'foo'
))
class
StringTest
(
BaseTest
):
...
...
Misc/NEWS
Dosyayı görüntüle @
9730e335
...
...
@@ -18,6 +18,10 @@ Core and Builtins
Library
-------
- Issue #3693: Make the error message more helpful when the array.array()
constructor is given a str. Move the array module typecode documentation to
the docstring of the constructor.
- Issue #19698: Removed exec_module() methods from
importlib.machinery.BuiltinImporter and ExtensionFileLoader.
...
...
Modules/arraymodule.c
Dosyayı görüntüle @
9730e335
...
...
@@ -2518,6 +2518,20 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
!
PyArg_ParseTuple
(
args
,
"C|O:array"
,
&
c
,
&
initial
))
return
NULL
;
if
(
initial
&&
c
!=
'u'
)
{
if
(
PyUnicode_Check
(
initial
))
{
PyErr_Format
(
PyExc_TypeError
,
"cannot use a str to initialize "
"an array with typecode '%c'"
,
c
);
return
NULL
;
}
else
if
(
array_Check
(
initial
)
&&
((
arrayobject
*
)
initial
)
->
ob_descr
->
typecode
==
'u'
)
{
PyErr_Format
(
PyExc_TypeError
,
"cannot use a unicode array to "
"initialize an array with typecode '%c'"
,
c
);
return
NULL
;
}
}
if
(
!
(
initial
==
NULL
||
PyList_Check
(
initial
)
||
PyByteArray_Check
(
initial
)
||
PyBytes_Check
(
initial
)
...
...
@@ -2644,9 +2658,19 @@ PyDoc_STRVAR(module_doc,
"This module defines an object type which can efficiently represent
\n
\
an array of basic values: characters, integers, floating point
\n
\
numbers. Arrays are sequence types and behave very much like lists,
\n
\
except that the type of objects stored in them is constrained. The
\n
\
type is specified at object creation time by using a type code, which
\n
\
is a single character. The following type codes are defined:
\n
\
except that the type of objects stored in them is constrained.
\n
"
);
PyDoc_STRVAR
(
arraytype_doc
,
"array(typecode [, initializer]) -> array
\n
\
\n
\
Return a new array whose items are restricted by typecode, and
\n
\
initialized from the optional initializer value, which must be a list,
\n
\
string or iterable over elements of the appropriate type.
\n
\
\n
\
Arrays represent basic values and behave very much like lists, except
\n
\
the type of objects stored in them is constrained. The type is specified
\n
\
at object creation time by using a type code, which is a single character.
\n
\
The following type codes are defined:
\n
\
\n
\
Type code C Type Minimum size in bytes
\n
\
'b' signed integer 1
\n
\
...
...
@@ -2670,21 +2694,6 @@ NOTE: The 'q' and 'Q' type codes are only available if the platform \n\
C compiler used to build Python supports 'long long', or, on Windows,
\n
\
'__int64'.
\n
\
\n
\
The constructor is:
\n
\
\n
\
array(typecode [, initializer]) -- create a new array
\n
\
"
);
PyDoc_STRVAR
(
arraytype_doc
,
"array(typecode [, initializer]) -> array
\n
\
\n
\
Return a new array whose items are restricted by typecode, and
\n
\
initialized from the optional initializer value, which must be a list,
\n
\
string or iterable over elements of the appropriate type.
\n
\
\n
\
Arrays represent basic values and behave very much like lists, except
\n
\
the type of objects stored in them is constrained.
\n
\
\n
\
Methods:
\n
\
\n
\
append() -- append a new item to the end of the array
\n
\
...
...
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