Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
17689991
Kaydet (Commit)
17689991
authored
Agu 24, 2010
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
only catch AttributeError in hasattr() #9666
üst
9cf5ef4c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
17 deletions
+19
-17
functions.rst
Doc/library/functions.rst
+4
-4
test_builtin.py
Lib/test/test_builtin.py
+6
-5
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+3
-0
bltinmodule.c
Python/bltinmodule.c
+5
-8
No files found.
Doc/library/functions.rst
Dosyayı görüntüle @
17689991
...
...
@@ -463,10 +463,10 @@ are always available. They are listed here in alphabetical order.
.. function:: hasattr(object, name)
The arguments are an object and a string. The result is ``True`` if the
string
is the name of one of the object's attributes, ``False`` if not. (This
is
i
mplemented by calling ``getattr(object, name)`` and seeing whether it raises an
exception
or not.)
The arguments are an object and a string. The result is ``True`` if the
string is the name of one of the object's attributes, ``False`` if not. (Th
is
i
s implemented by calling ``getattr(object, name)`` and seeing whether it
raises an :exc:`AttributeError`
or not.)
.. function:: hash(object)
...
...
Lib/test/test_builtin.py
Dosyayı görüntüle @
17689991
...
...
@@ -495,15 +495,16 @@ class BuiltinTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
hasattr
)
self
.
assertEqual
(
False
,
hasattr
(
sys
,
chr
(
sys
.
maxunicode
)))
# Check that hasattr allows SystemExit and KeyboardInterrupts by
# Check that hasattr propagates all exceptions outside of
# AttributeError.
class
A
:
def
__getattr__
(
self
,
what
):
raise
KeyboardInterrup
t
self
.
assertRaises
(
KeyboardInterrup
t
,
hasattr
,
A
(),
"b"
)
raise
SystemExi
t
self
.
assertRaises
(
SystemExi
t
,
hasattr
,
A
(),
"b"
)
class
B
:
def
__getattr__
(
self
,
what
):
raise
SystemExit
self
.
assertRaises
(
SystemExit
,
hasattr
,
B
(),
"b"
)
raise
ValueError
self
.
assertRaises
(
ValueError
,
hasattr
,
B
(),
"b"
)
def
test_hash
(
self
):
hash
(
None
)
...
...
Misc/ACKS
Dosyayı görüntüle @
17689991
...
...
@@ -730,6 +730,7 @@ Steven Scott
Barry Scott
Nick Seidenman
Žiga Seilnach
Yury Selivanov
Fred Sells
Jiwon Seo
Roger D. Serwy
...
...
Misc/NEWS
Dosyayı görüntüle @
17689991
...
...
@@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 2?
Core and Builtins
-----------------
- Issue #9666: Only catch AttributeError in hasattr(). All other exceptions that
occur during attribute lookup are now propagated to the caller.
- Issue #8622: Add PYTHONFSENCODING environment variable to override the
filesystem encoding.
...
...
Python/bltinmodule.c
Dosyayı görüntüle @
17689991
...
...
@@ -893,24 +893,21 @@ builtin_hasattr(PyObject *self, PyObject *args)
}
v
=
PyObject_GetAttr
(
v
,
name
);
if
(
v
==
NULL
)
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_Exception
))
return
NULL
;
else
{
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
PyErr_Clear
();
Py_INCREF
(
Py_False
);
return
Py_False
;
Py_RETURN_FALSE
;
}
return
NULL
;
}
Py_DECREF
(
v
);
Py_INCREF
(
Py_True
);
return
Py_True
;
Py_RETURN_TRUE
;
}
PyDoc_STRVAR
(
hasattr_doc
,
"hasattr(object, name) -> bool
\n
\
\n
\
Return whether the object has an attribute with the given name.
\n
\
(This is done by calling getattr(object, name) and catching
exceptions
.)"
);
(This is done by calling getattr(object, name) and catching
AttributeError
.)"
);
static
PyObject
*
...
...
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