diff options
author | Damien George <damien.p.george@gmail.com> | 2018-05-10 23:03:30 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-05-10 23:03:30 +1000 |
commit | 529860643bc321267376272356886ef39c4c6bd1 (patch) | |
tree | 5b4dac5760e2b498a5be83aaa9749ef958dd3aee /tests/basics/builtin_hasattr.py | |
parent | bc87b862fd22afb38ed7392b69474286fa5fe19f (diff) |
py/modbuiltins: Make built-in hasattr work properly for user types.
It now allows __getattr__ in a user type to raise AttributeError when the
attribute does not exist.
Diffstat (limited to 'tests/basics/builtin_hasattr.py')
-rw-r--r-- | tests/basics/builtin_hasattr.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/tests/basics/builtin_hasattr.py b/tests/basics/builtin_hasattr.py index 118a19e57..c60033b96 100644 --- a/tests/basics/builtin_hasattr.py +++ b/tests/basics/builtin_hasattr.py @@ -21,12 +21,19 @@ class C: def __getattr__(self, attr): if attr == "exists": return attr + elif attr == "raise": + raise Exception(123) raise AttributeError c = C() print(hasattr(c, "exists")) -# TODO -#print(hasattr(c, "doesnt_exist")) +print(hasattr(c, "doesnt_exist")) + +# ensure that non-AttributeError exceptions propagate out of hasattr +try: + hasattr(c, "raise") +except Exception as er: + print(er) try: hasattr(1, b'123') |