From 1bb37b6857383b585adb0a09644ee28960c1a5cc Mon Sep 17 00:00:00 2001 From: Dmitry Tyurnikov Date: Fri, 11 Sep 2015 13:05:15 +0100 Subject: [PATCH] Some lambda were replaced on def Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier. Yes: def f(x): return 2*x No: f = lambda x: 2*x https://www.python.org/dev/peps/pep-0008/ Change-Id: I776b80bb4bc2184125f461c801897f84d3f29254 --- doc/source/ext/resources.py | 5 ++++- heat/api/aws/utils.py | 4 +++- heat/api/openstack/v1/events.py | 8 ++++++-- heat/api/openstack/v1/resources.py | 4 +++- heat/common/short_id.py | 5 ++++- heat/db/sqlalchemy/api.py | 9 +++++++-- heat/engine/resources/openstack/heat/resource_group.py | 5 ++++- heat/engine/scheduler.py | 5 ++++- heat/engine/service.py | 9 +++++---- heat/tests/engine/test_dependencies.py | 4 +++- heat/tests/test_properties.py | 5 ++++- heat/tests/test_template.py | 5 ++++- heat/tests/utils.py | 3 +-- 13 files changed, 52 insertions(+), 19 deletions(-) diff --git a/doc/source/ext/resources.py b/doc/source/ext/resources.py index 1ecc7a851b..7f561e09b9 100644 --- a/doc/source/ext/resources.py +++ b/doc/source/ext/resources.py @@ -140,7 +140,10 @@ class ResourcePages(compat.Directive): if not prop: return 'Value' if prop.type == properties.Schema.LIST: - schema = lambda i: prop.schema[i] if prop.schema else None + + def schema(i): + return prop.schema[i] if prop.schema else None + sub_type = [self._prop_syntax_example(schema(i)) for i in range(2)] return '[%s, %s, ...]' % tuple(sub_type) diff --git a/heat/api/aws/utils.py b/heat/api/aws/utils.py index ab5f7c010a..84b31b8df6 100644 --- a/heat/api/aws/utils.py +++ b/heat/api/aws/utils.py @@ -79,7 +79,9 @@ def extract_param_list(params, prefix=''): yield (index, (key, value)) # Sort and group by index - key_func = lambda d: d[0] + def key_func(d): + return d[0] + data = sorted(get_param_data(params), key=key_func) members = itertools.groupby(data, key_func) diff --git a/heat/api/openstack/v1/events.py b/heat/api/openstack/v1/events.py index aa8d360e2c..806f603214 100644 --- a/heat/api/openstack/v1/events.py +++ b/heat/api/openstack/v1/events.py @@ -37,7 +37,9 @@ summary_keys = [ def format_event(req, event, keys=None): - include_key = lambda k: k in keys if keys else True + + def include_key(k): + return k in keys if keys else True def transform(key, value): if not include_key(key): @@ -132,7 +134,9 @@ class EventController(object): events = self._event_list(req, identity, filters=filter_params, **params) else: - res_match = lambda e: e[rpc_api.EVENT_RES_NAME] == resource_name + + def res_match(e): + return e[rpc_api.EVENT_RES_NAME] == resource_name events = self._event_list(req, identity, res_match, filters=filter_params, **params) diff --git a/heat/api/openstack/v1/resources.py b/heat/api/openstack/v1/resources.py index b0de2cac59..404571cdc4 100644 --- a/heat/api/openstack/v1/resources.py +++ b/heat/api/openstack/v1/resources.py @@ -27,7 +27,9 @@ from heat.rpc import client as rpc_client def format_resource(req, res, keys=None): keys = keys or [] - include_key = lambda k: k in keys if keys else True + + def include_key(k): + return k in keys if keys else True def transform(key, value): if not include_key(key): diff --git a/heat/common/short_id.py b/heat/common/short_id.py index c6854a8c8b..afd7a5cd05 100644 --- a/heat/common/short_id.py +++ b/heat/common/short_id.py @@ -31,7 +31,10 @@ def _to_byte_string(value, num_bits): required. """ shifts = six.moves.xrange(num_bits - 8, -8, -8) - byte_at = lambda off: (value >> off if off >= 0 else value << -off) & 0xff + + def byte_at(off): + return (value >> off if off >= 0 else value << -off) & 0xff + return ''.join(six.unichr(byte_at(offset)) for offset in shifts) diff --git a/heat/db/sqlalchemy/api.py b/heat/db/sqlalchemy/api.py index f137bd69aa..ec455589ac 100644 --- a/heat/db/sqlalchemy/api.py +++ b/heat/db/sqlalchemy/api.py @@ -56,8 +56,13 @@ def get_facade(): return _facade -get_engine = lambda: get_facade().get_engine() -get_session = lambda: get_facade().get_session() + +def get_engine(): + return get_facade().get_engine() + + +def get_session(): + return get_facade().get_session() def get_backend(): diff --git a/heat/engine/resources/openstack/heat/resource_group.py b/heat/engine/resources/openstack/heat/resource_group.py index 6a340994f2..2ca41b6b1a 100644 --- a/heat/engine/resources/openstack/heat/resource_group.py +++ b/heat/engine/resources/openstack/heat/resource_group.py @@ -464,7 +464,10 @@ class ResourceGroup(stack_resource.StackResource): def _handle_repl_val(self, res_name, val): repl_var = self.properties[self.INDEX_VAR] - recurse = lambda x: self._handle_repl_val(res_name, x) + + def recurse(x): + return self._handle_repl_val(res_name, x) + if isinstance(val, six.string_types): return val.replace(repl_var, res_name) elif isinstance(val, collections.Mapping): diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index 2acb038333..d98c1597d8 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -423,5 +423,8 @@ class DependencyTaskGroup(object): Subtasks have been started but have not yet completed. """ - running = lambda k_r: k_r[0] in self._graph and k_r[1].started() + + def running(k_r): + return k_r[0] in self._graph and k_r[1].started() + return six.moves.filter(running, six.iteritems(self._runners)) diff --git a/heat/engine/service.py b/heat/engine/service.py index 4874f60554..bd46089529 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -891,10 +891,11 @@ class EngineService(service.Service): actions = update_task.preview() - fmt_updated_res = lambda k: api.format_stack_resource( - updated_stack.resources.get(k)) - fmt_current_res = lambda k: api.format_stack_resource( - current_stack.resources.get(k)) + def fmt_updated_res(k): + return api.format_stack_resource(updated_stack.resources.get(k)) + + def fmt_current_res(k): + return api.format_stack_resource(current_stack.resources.get(k)) return { 'unchanged': map(fmt_updated_res, actions['unchanged']), diff --git a/heat/tests/engine/test_dependencies.py b/heat/tests/engine/test_dependencies.py index 02df12bca6..53dc4ff460 100644 --- a/heat/tests/engine/test_dependencies.py +++ b/heat/tests/engine/test_dependencies.py @@ -162,7 +162,9 @@ class dependenciesTest(common.HeatTestCase): def test_noexist_partial(self): d = dependencies.Dependencies([('foo', 'bar')]) - get = lambda i: d[i] + + def get(i): + return d[i] self.assertRaises(KeyError, get, 'baz') def test_single_partial(self): diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index b478749432..b9e74b4eac 100644 --- a/heat/tests/test_properties.py +++ b/heat/tests/test_properties.py @@ -1011,7 +1011,10 @@ class PropertiesTest(common.HeatTestCase): 'bad_int': 'foo', 'default_override': 21, } - double = lambda d: d * 2 + + def double(d): + return d * 2 + self.props = properties.Properties(schema, data, double, 'wibble') def test_integer_good(self): diff --git a/heat/tests/test_template.py b/heat/tests/test_template.py index c62f781520..29477faa52 100644 --- a/heat/tests/test_template.py +++ b/heat/tests/test_template.py @@ -1083,7 +1083,10 @@ class TemplateFnErrorTest(common.HeatTestCase): def test_bad_input(self): tmpl = template.Template(empty_template) - resolve = lambda s: TemplateTest.resolve(s, tmpl) + + def resolve(s): + return TemplateTest.resolve(s, tmpl) + error = self.assertRaises(self.expect, resolve, self.snippet) diff --git a/heat/tests/utils.py b/heat/tests/utils.py index 3126aa11cf..3ff3f60c47 100644 --- a/heat/tests/utils.py +++ b/heat/tests/utils.py @@ -38,8 +38,7 @@ class UUIDStub(object): def __enter__(self): self.uuid4 = uuid.uuid4 - uuid_stub = lambda: self.value - uuid.uuid4 = uuid_stub + uuid.uuid4 = lambda: self.value def __exit__(self, *exc_info): uuid.uuid4 = self.uuid4