summaryrefslogtreecommitdiff
path: root/glance/hacking
diff options
context:
space:
mode:
authorChangBo Guo(gcb) <eric.guo@easystack.cn>2015-03-05 17:31:56 +0800
committerChangBo Guo(gcb) <eric.guo@easystack.cn>2015-03-18 20:20:33 +0800
commit27539859ece47e4654736b905d75de5399d25ccc (patch)
tree706c8de409a08c97489040de88af22c2de392fd2 /glance/hacking
parentea7622dcf324db565825ddf893b88f7a273bdf3f (diff)
downloadglance-27539859ece47e4654736b905d75de5399d25ccc.tar.gz
Remove use of contextlib.nested
The contextlib.nested call has been deprecated in Python 2.7. This causes DeprecationWarning messages in the unit tests. There are also known issues with contextlib.nested that were addressed by the native support for multiple "with" variables. For instance, if the first object is created but the second one throws an exception, the first object's __exit__ is never called. For more information see https://docs.python.org/2/library/contextlib.html#contextlib.nested contextlib.nested is also not compatible in Python 3. Since Glance no longer supports 2.6 we can remove the use of these contextlib.nested calls. Added hacking check to catch if any new instances are added to the codebase. Closes-Bug: #1428424 Change-Id: Ic8edfa41d6c468cf6db8d11d3533e4f8cf2053c2
Diffstat (limited to 'glance/hacking')
-rw-r--r--glance/hacking/checks.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/glance/hacking/checks.py b/glance/hacking/checks.py
index a79f3f59a..bb41e7c25 100644
--- a/glance/hacking/checks.py
+++ b/glance/hacking/checks.py
@@ -139,6 +139,15 @@ def validate_log_translations(logical_line, physical_line, filename):
yield (0, msg)
+def check_no_contextlib_nested(logical_line):
+ msg = ("G327: contextlib.nested is deprecated since Python 2.7. See "
+ "https://docs.python.org/2/library/contextlib.html#contextlib."
+ "nested for more information.")
+ if ("with contextlib.nested(" in logical_line or
+ "with nested(" in logical_line):
+ yield(0, msg)
+
+
def factory(register):
register(assert_true_instance)
register(assert_equal_type)
@@ -146,3 +155,4 @@ def factory(register):
register(no_translate_debug_logs)
register(no_direct_use_of_unicode_function)
register(validate_log_translations)
+ register(check_no_contextlib_nested)