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
=== modified file 'src/lazr/restful/docs/utils.rst'
--- src/lazr/restful/docs/utils.rst 2020-09-06 22:57:35 +0000
+++ src/lazr/restful/docs/utils.rst 2021-01-21 00:48:28 +0000
@@ -297,6 +297,9 @@
297caller. This behaviour of the builtin hasattr() is annoying because it297caller. This behaviour of the builtin hasattr() is annoying because it
298makes problems harder to diagnose.298makes problems harder to diagnose.
299299
300(The builtin hasattr() is fixed as of Python 3.2.)
301
302 >>> import sys
300 >>> from lazr.restful.utils import safe_hasattr303 >>> from lazr.restful.utils import safe_hasattr
301304
302 >>> class Oracle(object):305 >>> class Oracle(object):
@@ -304,12 +307,15 @@
304 ... def is_full_moon(self):307 ... def is_full_moon(self):
305 ... return full_moon308 ... return full_moon
306 >>> oracle = Oracle()309 >>> oracle = Oracle()
307 >>> hasattr(oracle, 'is_full_moon')310 >>> if sys.version_info[:2] < (3, 2):
311 ... hasattr(oracle, 'is_full_moon')
312 ... else:
313 ... False
308 False314 False
309 >>> safe_hasattr(oracle, 'is_full_moon')315 >>> safe_hasattr(oracle, 'is_full_moon')
310 Traceback (most recent call last):316 Traceback (most recent call last):
311 ...317 ...
312 NameError: global name 'full_moon' is not defined318 NameError: ...name 'full_moon' is not defined
313319
314 >>> full_moon = True320 >>> full_moon = True
315 >>> hasattr(oracle, 'is_full_moon')321 >>> hasattr(oracle, 'is_full_moon')

Subscribers

People subscribed via source and target branches