From 27539859ece47e4654736b905d75de5399d25ccc Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Thu, 5 Mar 2015 17:31:56 +0800 Subject: 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 --- glance/hacking/checks.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'glance/hacking') 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) -- cgit v1.2.1