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
b9030f4f
Commit
b9030f4f
authored
May 12, 2008
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#2196 hasattr now allows SystemExit and KeyboardInterrupt to propagate
parent
42bfa90f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
3 deletions
+20
-3
Lib/test/test_builtin.py
Lib/test/test_builtin.py
+10
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/bltinmodule.c
Python/bltinmodule.c
+7
-3
No files found.
Lib/test/test_builtin.py
View file @
b9030f4f
...
...
@@ -590,6 +590,16 @@ class BuiltinTest(unittest.TestCase):
if
have_unicode
:
self
.
assertRaises
(
UnicodeError
,
hasattr
,
sys
,
unichr
(
sys
.
maxunicode
))
# Check that hasattr allows SystemExit and KeyboardInterrupts by
class
A
:
def
__getattr__
(
self
,
what
):
raise
KeyboardInterrupt
self
.
assertRaises
(
KeyboardInterrupt
,
hasattr
,
A
(),
"b"
)
class
B
:
def
__getattr__
(
self
,
what
):
raise
SystemExit
self
.
assertRaises
(
SystemExit
,
hasattr
,
B
(),
"b"
)
def
test_hash
(
self
):
hash
(
None
)
self
.
assertEqual
(
hash
(
1
),
hash
(
1L
))
...
...
Misc/NEWS
View file @
b9030f4f
...
...
@@ -17,6 +17,9 @@ Core and Builtins
- Issue #2790: sys.flags was not properly exposing its bytes_warning attribute.
- Issue #2196: hasattr now lets exceptions which do not inherit Exception
(KeyboardInterrupt, and SystemExit) propagate instead of ignoring them
Extension Modules
-----------------
...
...
Python/bltinmodule.c
View file @
b9030f4f
...
...
@@ -877,10 +877,14 @@ builtin_hasattr(PyObject *self, PyObject *args)
}
v
=
PyObject_GetAttr
(
v
,
name
);
if
(
v
==
NULL
)
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_Exception
))
return
NULL
;
else
{
PyErr_Clear
();
Py_INCREF
(
Py_False
);
return
Py_False
;
}
}
Py_DECREF
(
v
);
Py_INCREF
(
Py_True
);
return
Py_True
;
...
...
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