mirror of
https://github.com/python/cpython.git
synced 2025-11-29 06:22:10 +00:00
Add hasattr() example.
This commit is contained in:
parent
a275c989c9
commit
03ca1a92af
1 changed files with 12 additions and 1 deletions
|
|
@ -456,7 +456,18 @@ Some smaller changes made to the core Python language are:
|
||||||
would otherwise be absent from the class dictionary. Formerly, *hasattr*
|
would otherwise be absent from the class dictionary. Formerly, *hasattr*
|
||||||
would catch any exception, possibly masking genuine errors. Now, *hasattr*
|
would catch any exception, possibly masking genuine errors. Now, *hasattr*
|
||||||
has been tightened to only catch :exc:`AttributeError` and let other
|
has been tightened to only catch :exc:`AttributeError` and let other
|
||||||
exceptions pass through.
|
exceptions pass through::
|
||||||
|
|
||||||
|
>>> class A:
|
||||||
|
@property
|
||||||
|
def f(self):
|
||||||
|
return 1 // 0
|
||||||
|
|
||||||
|
>>> a = A()
|
||||||
|
>>> hasattr(a, 'f')
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ZeroDivisionError: integer division or modulo by zero
|
||||||
|
|
||||||
(Discovered by Yury Selivanov and fixed by Benjamin Peterson; :issue:`9666`.)
|
(Discovered by Yury Selivanov and fixed by Benjamin Peterson; :issue:`9666`.)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue