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
87e5006d
Commit
87e5006d
authored
May 25, 2009
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle errors from _PyObject_LookupSpecial when __get__ fails
parent
176a56c6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
8 deletions
+40
-8
Lib/test/test_descr.py
Lib/test/test_descr.py
+17
-1
Objects/abstract.c
Objects/abstract.c
+11
-2
Objects/enumobject.c
Objects/enumobject.c
+4
-1
Objects/object.c
Objects/object.c
+2
-0
Python/sysmodule.c
Python/sysmodule.c
+6
-4
No files found.
Lib/test/test_descr.py
View file @
87e5006d
...
...
@@ -1722,7 +1722,11 @@ order (MRO) for bases """
def
__get__
(
self
,
obj
,
owner
):
record
.
append
(
1
)
return
self
.
impl
.
__get__
(
obj
,
owner
)
class
MyException
(
Exception
):
pass
class
ErrDescr
(
object
):
def
__get__
(
self
,
obj
,
owner
):
raise
MyException
for
name
,
runner
,
meth_impl
,
ok
,
env
in
specials
:
class
X
(
Checker
):
...
...
@@ -1741,6 +1745,18 @@ order (MRO) for bases """
runner
(
X
())
self
.
assertEqual
(
record
,
[
1
],
name
)
class
X
(
Checker
):
pass
for
attr
,
obj
in
env
.
iteritems
():
setattr
(
X
,
attr
,
obj
)
setattr
(
X
,
name
,
ErrDescr
())
try
:
runner
(
X
())
except
MyException
:
pass
else
:
self
.
fail
(
"{0!r} didn't raise"
.
format
(
name
))
def
test_specials
(
self
):
# Testing special operators...
# Test operators like __hash__ for which a built-in default exists
...
...
Objects/abstract.c
View file @
87e5006d
...
...
@@ -111,8 +111,12 @@ _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
return
defaultvalue
;
/* try o.__length_hint__() */
hintmeth
=
_PyObject_LookupSpecial
(
o
,
"__length_hint__"
,
&
hintstrobj
);
if
(
hintmeth
==
NULL
)
if
(
hintmeth
==
NULL
)
{
if
(
PyErr_Occurred
())
return
-
1
;
else
return
defaultvalue
;
}
ro
=
PyObject_CallFunctionObjArgs
(
hintmeth
,
NULL
);
Py_DECREF
(
hintmeth
);
if
(
ro
==
NULL
)
{
...
...
@@ -2945,6 +2949,8 @@ PyObject_IsInstance(PyObject *inst, PyObject *cls)
}
return
ok
;
}
else
if
(
PyErr_Occurred
())
return
-
1
;
}
return
recursive_isinstance
(
inst
,
cls
);
}
...
...
@@ -3021,6 +3027,9 @@ PyObject_IsSubclass(PyObject *derived, PyObject *cls)
}
return
ok
;
}
else
if
(
PyErr_Occurred
())
{
return
-
1
;
}
}
return
recursive_issubclass
(
derived
,
cls
);
}
...
...
Objects/enumobject.c
View file @
87e5006d
...
...
@@ -241,9 +241,12 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
NULL
;
}
}
else
else
{
reversed_meth
=
_PyObject_LookupSpecial
(
seq
,
"__reversed__"
,
&
reversed_cache
);
if
(
reversed_meth
==
NULL
&&
PyErr_Occurred
())
return
NULL
;
}
if
(
reversed_meth
!=
NULL
)
{
PyObject
*
res
=
PyObject_CallFunctionObjArgs
(
reversed_meth
,
NULL
);
Py_DECREF
(
reversed_meth
);
...
...
Objects/object.c
View file @
87e5006d
...
...
@@ -509,6 +509,8 @@ PyObject_Unicode(PyObject *v)
res
=
PyObject_CallFunctionObjArgs
(
func
,
NULL
);
Py_DECREF
(
func
);
}
else
if
(
PyErr_Occurred
())
return
NULL
;
}
/* Didn't find __unicode__ */
...
...
Python/sysmodule.c
View file @
87e5006d
...
...
@@ -669,10 +669,12 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)
else
{
PyObject
*
method
=
_PyObject_LookupSpecial
(
o
,
"__sizeof__"
,
&
str__sizeof__
);
if
(
method
==
NULL
)
if
(
method
==
NULL
)
{
if
(
!
PyErr_Occurred
())
PyErr_Format
(
PyExc_TypeError
,
"Type %.100s doesn't define __sizeof__"
,
Py_TYPE
(
o
)
->
tp_name
);
}
else
{
res
=
PyObject_CallFunctionObjArgs
(
method
,
NULL
);
Py_DECREF
(
method
);
...
...
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