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
a6c0c069
Commit
a6c0c069
authored
Sep 20, 2017
by
Serhiy Storchaka
Committed by
Nick Coghlan
Sep 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31506: Improve the error message logic for object.__new__ and object.__init__. (GH-3650)
parent
d6e2f26f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
Misc/NEWS.d/next/Core and Builtins/2017-09-19-10-29-36.bpo-31506.pRVTRB.rst
...ore and Builtins/2017-09-19-10-29-36.bpo-31506.pRVTRB.rst
+1
-0
Objects/typeobject.c
Objects/typeobject.c
+21
-10
No files found.
Misc/NEWS.d/next/Core and Builtins/2017-09-19-10-29-36.bpo-31506.pRVTRB.rst
0 → 100644
View file @
a6c0c069
Improved the error message logic for object.__new__ and object.__init__.
Objects/typeobject.c
View file @
a6c0c069
...
...
@@ -3543,23 +3543,34 @@ excess_args(PyObject *args, PyObject *kwds)
static
int
object_init
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
int
err
=
0
;
PyTypeObject
*
type
=
Py_TYPE
(
self
);
if
(
excess_args
(
args
,
kwds
)
&&
(
type
->
tp_new
==
object_new
||
type
->
tp_init
!=
object_init
))
{
PyErr_SetString
(
PyExc_TypeError
,
"object.__init__() takes no parameters"
);
err
=
-
1
;
if
(
excess_args
(
args
,
kwds
))
{
if
(
type
->
tp_init
!=
object_init
)
{
PyErr_SetString
(
PyExc_TypeError
,
"object() takes no arguments"
);
return
-
1
;
}
if
(
type
->
tp_new
==
object_new
)
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s() takes no arguments"
,
type
->
tp_name
);
return
-
1
;
}
}
return
err
;
return
0
;
}
static
PyObject
*
object_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
if
(
excess_args
(
args
,
kwds
)
&&
(
type
->
tp_init
==
object_init
||
type
->
tp_new
!=
object_new
))
{
PyErr_SetString
(
PyExc_TypeError
,
"object() takes no parameters"
);
return
NULL
;
if
(
excess_args
(
args
,
kwds
))
{
if
(
type
->
tp_new
!=
object_new
)
{
PyErr_SetString
(
PyExc_TypeError
,
"object() takes no arguments"
);
return
NULL
;
}
if
(
type
->
tp_init
==
object_init
)
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s() takes no arguments"
,
type
->
tp_name
);
return
NULL
;
}
}
if
(
type
->
tp_flags
&
Py_TPFLAGS_IS_ABSTRACT
)
{
...
...
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