Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03ca1a9

Browse files
committed
Add hasattr() example.
1 parent a275c98 commit 03ca1a9

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

Doc/whatsnew/3.2.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,18 @@ Some smaller changes made to the core Python language are:
456456
would otherwise be absent from the class dictionary. Formerly, *hasattr*
457457
would catch any exception, possibly masking genuine errors. Now, *hasattr*
458458
has been tightened to only catch :exc:`AttributeError` and let other
459-
exceptions pass through.
459+
exceptions pass through::
460+
461+
>>> class A:
462+
@property
463+
def f(self):
464+
return 1 // 0
465+
466+
>>> a = A()
467+
>>> hasattr(a, 'f')
468+
Traceback (most recent call last):
469+
...
470+
ZeroDivisionError: integer division or modulo by zero
460471

461472
(Discovered by Yury Selivanov and fixed by Benjamin Peterson; :issue:`9666`.)
462473

0 commit comments

Comments
 (0)