Mercurial > cpython-lru_cache-weakref
comparison Modules/arraymodule.c @ 87647:2c87d3944c7a
Issue #3693: Fix array obscure error message when given a str.
| author | Alexandre Vassalotti <alexandre@peadrop.com> |
|---|---|
| date | Fri, 29 Nov 2013 20:47:15 -0800 |
| parents | 285d28c3620a |
| children |
comparison
equal
deleted
inserted
replaced
| 87646:b0e180f8e588 | 87647:2c87d3944c7a |
|---|---|
| 2516 return NULL; | 2516 return NULL; |
| 2517 | 2517 |
| 2518 if (!PyArg_ParseTuple(args, "C|O:array", &c, &initial)) | 2518 if (!PyArg_ParseTuple(args, "C|O:array", &c, &initial)) |
| 2519 return NULL; | 2519 return NULL; |
| 2520 | 2520 |
| 2521 if (initial && c != 'u') { | |
| 2522 if (PyUnicode_Check(initial)) { | |
| 2523 PyErr_Format(PyExc_TypeError, "cannot use a str to initialize " | |
| 2524 "an array with typecode '%c'", c); | |
| 2525 return NULL; | |
| 2526 } | |
| 2527 else if (array_Check(initial) && | |
| 2528 ((arrayobject*)initial)->ob_descr->typecode == 'u') { | |
| 2529 PyErr_Format(PyExc_TypeError, "cannot use a unicode array to " | |
| 2530 "initialize an array with typecode '%c'", c); | |
| 2531 return NULL; | |
| 2532 } | |
| 2533 } | |
| 2534 | |
| 2521 if (!(initial == NULL || PyList_Check(initial) | 2535 if (!(initial == NULL || PyList_Check(initial) |
| 2522 || PyByteArray_Check(initial) | 2536 || PyByteArray_Check(initial) |
| 2523 || PyBytes_Check(initial) | 2537 || PyBytes_Check(initial) |
| 2524 || PyTuple_Check(initial) | 2538 || PyTuple_Check(initial) |
| 2525 || ((c=='u') && PyUnicode_Check(initial)) | 2539 || ((c=='u') && PyUnicode_Check(initial)) |
| 2642 | 2656 |
| 2643 PyDoc_STRVAR(module_doc, | 2657 PyDoc_STRVAR(module_doc, |
| 2644 "This module defines an object type which can efficiently represent\n\ | 2658 "This module defines an object type which can efficiently represent\n\ |
| 2645 an array of basic values: characters, integers, floating point\n\ | 2659 an array of basic values: characters, integers, floating point\n\ |
| 2646 numbers. Arrays are sequence types and behave very much like lists,\n\ | 2660 numbers. Arrays are sequence types and behave very much like lists,\n\ |
| 2647 except that the type of objects stored in them is constrained. The\n\ | 2661 except that the type of objects stored in them is constrained.\n"); |
| 2648 type is specified at object creation time by using a type code, which\n\ | 2662 |
| 2649 is a single character. The following type codes are defined:\n\ | 2663 PyDoc_STRVAR(arraytype_doc, |
| 2664 "array(typecode [, initializer]) -> array\n\ | |
| 2665 \n\ | |
| 2666 Return a new array whose items are restricted by typecode, and\n\ | |
| 2667 initialized from the optional initializer value, which must be a list,\n\ | |
| 2668 string or iterable over elements of the appropriate type.\n\ | |
| 2669 \n\ | |
| 2670 Arrays represent basic values and behave very much like lists, except\n\ | |
| 2671 the type of objects stored in them is constrained. The type is specified\n\ | |
| 2672 at object creation time by using a type code, which is a single character.\n\ | |
| 2673 The following type codes are defined:\n\ | |
| 2650 \n\ | 2674 \n\ |
| 2651 Type code C Type Minimum size in bytes \n\ | 2675 Type code C Type Minimum size in bytes \n\ |
| 2652 'b' signed integer 1 \n\ | 2676 'b' signed integer 1 \n\ |
| 2653 'B' unsigned integer 1 \n\ | 2677 'B' unsigned integer 1 \n\ |
| 2654 'u' Unicode character 2 (see note) \n\ | 2678 'u' Unicode character 2 (see note) \n\ |
| 2667 narrow builds this is 2-bytes on wide builds this is 4-bytes.\n\ | 2691 narrow builds this is 2-bytes on wide builds this is 4-bytes.\n\ |
| 2668 \n\ | 2692 \n\ |
| 2669 NOTE: The 'q' and 'Q' type codes are only available if the platform \n\ | 2693 NOTE: The 'q' and 'Q' type codes are only available if the platform \n\ |
| 2670 C compiler used to build Python supports 'long long', or, on Windows, \n\ | 2694 C compiler used to build Python supports 'long long', or, on Windows, \n\ |
| 2671 '__int64'.\n\ | 2695 '__int64'.\n\ |
| 2672 \n\ | |
| 2673 The constructor is:\n\ | |
| 2674 \n\ | |
| 2675 array(typecode [, initializer]) -- create a new array\n\ | |
| 2676 "); | |
| 2677 | |
| 2678 PyDoc_STRVAR(arraytype_doc, | |
| 2679 "array(typecode [, initializer]) -> array\n\ | |
| 2680 \n\ | |
| 2681 Return a new array whose items are restricted by typecode, and\n\ | |
| 2682 initialized from the optional initializer value, which must be a list,\n\ | |
| 2683 string or iterable over elements of the appropriate type.\n\ | |
| 2684 \n\ | |
| 2685 Arrays represent basic values and behave very much like lists, except\n\ | |
| 2686 the type of objects stored in them is constrained.\n\ | |
| 2687 \n\ | 2696 \n\ |
| 2688 Methods:\n\ | 2697 Methods:\n\ |
| 2689 \n\ | 2698 \n\ |
| 2690 append() -- append a new item to the end of the array\n\ | 2699 append() -- append a new item to the end of the array\n\ |
| 2691 buffer_info() -- return information giving the current memory info\n\ | 2700 buffer_info() -- return information giving the current memory info\n\ |
