Use of six.PY3 should be forward compatible
Care should be taken in using a condition like so: if six.PY3: foo() else: bar() This assumes PY2 and PY4 would behave the same. Rather the conditional should check for PY2 and use the else for PY3 and future versions of Python. http://astrofrog.github.io/blog/2016/01/12/stop-writing-python-4-incompatible-code/ Change-Id: I9bc00e2f01fe8fe970d6c5327207c08a90885cda
This commit is contained in:
parent
adeb0bfe4c
commit
be015dbb42
@ -63,13 +63,13 @@ logging.setup(CONF, 'nova')
|
|||||||
|
|
||||||
_TRUE_VALUES = ('True', 'true', '1', 'yes')
|
_TRUE_VALUES = ('True', 'true', '1', 'yes')
|
||||||
|
|
||||||
if six.PY3:
|
if six.PY2:
|
||||||
|
nested = contextlib.nested
|
||||||
|
else:
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def nested(*contexts):
|
def nested(*contexts):
|
||||||
with contextlib.ExitStack() as stack:
|
with contextlib.ExitStack() as stack:
|
||||||
yield [stack.enter_context(c) for c in contexts]
|
yield [stack.enter_context(c) for c in contexts]
|
||||||
else:
|
|
||||||
nested = contextlib.nested
|
|
||||||
|
|
||||||
|
|
||||||
class SampleNetworks(fixtures.Fixture):
|
class SampleNetworks(fixtures.Fixture):
|
||||||
|
@ -722,12 +722,12 @@ def monkey_patch():
|
|||||||
# If CONF.monkey_patch is not True, this function do nothing.
|
# If CONF.monkey_patch is not True, this function do nothing.
|
||||||
if not CONF.monkey_patch:
|
if not CONF.monkey_patch:
|
||||||
return
|
return
|
||||||
if six.PY3:
|
if six.PY2:
|
||||||
|
is_method = inspect.ismethod
|
||||||
|
else:
|
||||||
def is_method(obj):
|
def is_method(obj):
|
||||||
# Unbound methods became regular functions on Python 3
|
# Unbound methods became regular functions on Python 3
|
||||||
return inspect.ismethod(obj) or inspect.isfunction(obj)
|
return inspect.ismethod(obj) or inspect.isfunction(obj)
|
||||||
else:
|
|
||||||
is_method = inspect.ismethod
|
|
||||||
# Get list of modules and decorators
|
# Get list of modules and decorators
|
||||||
for module_and_decorator in CONF.monkey_patch_modules:
|
for module_and_decorator in CONF.monkey_patch_modules:
|
||||||
module, decorator_name = module_and_decorator.split(':')
|
module, decorator_name = module_and_decorator.split(':')
|
||||||
|
Loading…
Reference in New Issue
Block a user