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
193cd2fb
Commit
193cd2fb
authored
Jul 30, 2011
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Plain Diff
merge heads.
parents
3d23fd64
18d7d7a2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
0 deletions
+108
-0
Lib/test/test_builtin.py
Lib/test/test_builtin.py
+7
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/object.c
Objects/object.c
+69
-0
Objects/sliceobject.c
Objects/sliceobject.c
+29
-0
No files found.
Lib/test/test_builtin.py
View file @
193cd2fb
...
...
@@ -1343,6 +1343,13 @@ class BuiltinTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
x
.
translate
,
b"1"
,
1
)
self
.
assertRaises
(
TypeError
,
x
.
translate
,
b"1"
*
256
,
1
)
def
test_construct_singletons
(
self
):
for
const
in
None
,
Ellipsis
,
NotImplemented
:
tp
=
type
(
const
)
self
.
assertIs
(
tp
(),
const
)
self
.
assertRaises
(
TypeError
,
tp
,
1
,
2
)
self
.
assertRaises
(
TypeError
,
tp
,
a
=
1
,
b
=
2
)
class
TestSorted
(
unittest
.
TestCase
):
def
test_basic
(
self
):
...
...
Misc/NEWS
View file @
193cd2fb
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Make type(None), type(Ellipsis), and type(NotImplemented) callable. They
return the respective singleton instances.
- Forbid summing bytes in sum().
- Verify the types of AST strings and identifiers provided by the user before
...
...
Objects/object.c
View file @
193cd2fb
...
...
@@ -1277,6 +1277,16 @@ none_dealloc(PyObject* ignore)
Py_FatalError
(
"deallocating None"
);
}
static
PyObject
*
none_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
if
(
PyTuple_GET_SIZE
(
args
)
||
(
kwargs
&&
PyDict_Size
(
kwargs
)))
{
PyErr_SetString
(
PyExc_TypeError
,
"NoneType takes no arguments"
);
return
NULL
;
}
Py_RETURN_NONE
;
}
static
int
none_bool
(
PyObject
*
v
)
{
...
...
@@ -1335,6 +1345,30 @@ static PyTypeObject PyNone_Type = {
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
0
,
/*tp_hash */
0
,
/*tp_call */
0
,
/*tp_str */
0
,
/*tp_getattro */
0
,
/*tp_setattro */
0
,
/*tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/*tp_flags */
0
,
/*tp_doc */
0
,
/*tp_traverse */
0
,
/*tp_clear */
0
,
/*tp_richcompare */
0
,
/*tp_weaklistoffset */
0
,
/*tp_iter */
0
,
/*tp_iternext */
0
,
/*tp_methods */
0
,
/*tp_members */
0
,
/*tp_getset */
0
,
/*tp_base */
0
,
/*tp_dict */
0
,
/*tp_descr_get */
0
,
/*tp_descr_set */
0
,
/*tp_dictoffset */
0
,
/*tp_init */
0
,
/*tp_alloc */
none_new
,
/*tp_new */
};
PyObject
_Py_NoneStruct
=
{
...
...
@@ -1351,6 +1385,17 @@ NotImplemented_repr(PyObject *op)
return
PyUnicode_FromString
(
"NotImplemented"
);
}
static
PyObject
*
notimplemented_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
if
(
PyTuple_GET_SIZE
(
args
)
||
(
kwargs
&&
PyDict_Size
(
kwargs
)))
{
PyErr_SetString
(
PyExc_TypeError
,
"NotImplementedType takes no arguments"
);
return
NULL
;
}
Py_INCREF
(
Py_NotImplemented
);
return
Py_NotImplemented
;
}
static
PyTypeObject
PyNotImplemented_Type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
"NotImplementedType"
,
...
...
@@ -1366,6 +1411,30 @@ static PyTypeObject PyNotImplemented_Type = {
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
0
,
/*tp_hash */
0
,
/*tp_call */
0
,
/*tp_str */
0
,
/*tp_getattro */
0
,
/*tp_setattro */
0
,
/*tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/*tp_flags */
0
,
/*tp_doc */
0
,
/*tp_traverse */
0
,
/*tp_clear */
0
,
/*tp_richcompare */
0
,
/*tp_weaklistoffset */
0
,
/*tp_iter */
0
,
/*tp_iternext */
0
,
/*tp_methods */
0
,
/*tp_members */
0
,
/*tp_getset */
0
,
/*tp_base */
0
,
/*tp_dict */
0
,
/*tp_descr_get */
0
,
/*tp_descr_set */
0
,
/*tp_dictoffset */
0
,
/*tp_init */
0
,
/*tp_alloc */
notimplemented_new
,
/*tp_new */
};
PyObject
_Py_NotImplementedStruct
=
{
...
...
Objects/sliceobject.c
View file @
193cd2fb
...
...
@@ -16,6 +16,17 @@ this type and there is exactly one in existence.
#include "Python.h"
#include "structmember.h"
static
PyObject
*
ellipsis_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
if
(
PyTuple_GET_SIZE
(
args
)
||
(
kwargs
&&
PyDict_Size
(
kwargs
)))
{
PyErr_SetString
(
PyExc_TypeError
,
"EllipsisType takes no arguments"
);
return
NULL
;
}
Py_INCREF
(
Py_Ellipsis
);
return
Py_Ellipsis
;
}
static
PyObject
*
ellipsis_repr
(
PyObject
*
op
)
{
...
...
@@ -43,6 +54,24 @@ PyTypeObject PyEllipsis_Type = {
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/* tp_flags */
0
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_alloc */
ellipsis_new
,
/* tp_new */
};
PyObject
_Py_EllipsisObject
=
{
...
...
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