Merge lp:~cjwatson/lazr.restful/py3-safe-hasattr-tests into lp:lazr.restful

Proposed by Colin Watson
Status: Merged
Merged at revision: 289
Proposed branch: lp:~cjwatson/lazr.restful/py3-safe-hasattr-tests
Merge into: lp:lazr.restful
Diff against target: 31 lines (+8/-2)
1 file modified
src/lazr/restful/docs/utils.rst (+8/-2)
To merge this branch: bzr merge lp:~cjwatson/lazr.restful/py3-safe-hasattr-tests
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Cristian Gonzalez (community) Approve
Review via email: mp+396625@code.launchpad.net

Commit message

Adjust tests for hasattr() fix in Python 3.2.

Description of the change

Python 3.2 fixed hasattr() to only catch AttributeError rather than masking other errors, giving it similar behaviour to safe_hasattr() for most purposes. Adjust the tests to handle this.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restful/docs/utils.rst'
2--- src/lazr/restful/docs/utils.rst 2020-09-06 22:57:35 +0000
3+++ src/lazr/restful/docs/utils.rst 2021-01-21 00:48:28 +0000
4@@ -297,6 +297,9 @@
5 caller. This behaviour of the builtin hasattr() is annoying because it
6 makes problems harder to diagnose.
7
8+(The builtin hasattr() is fixed as of Python 3.2.)
9+
10+ >>> import sys
11 >>> from lazr.restful.utils import safe_hasattr
12
13 >>> class Oracle(object):
14@@ -304,12 +307,15 @@
15 ... def is_full_moon(self):
16 ... return full_moon
17 >>> oracle = Oracle()
18- >>> hasattr(oracle, 'is_full_moon')
19+ >>> if sys.version_info[:2] < (3, 2):
20+ ... hasattr(oracle, 'is_full_moon')
21+ ... else:
22+ ... False
23 False
24 >>> safe_hasattr(oracle, 'is_full_moon')
25 Traceback (most recent call last):
26 ...
27- NameError: global name 'full_moon' is not defined
28+ NameError: ...name 'full_moon' is not defined
29
30 >>> full_moon = True
31 >>> hasattr(oracle, 'is_full_moon')

Subscribers

People subscribed via source and target branches