Replace map/filter lambda with comprehensions

List comprehensions and generator expressions are considered to be more
Pythonic (and usually more readable) than map and filter with lambda.
This patch replaces four usages of [map|filter](lambda ...) with the
appropriate list comprehension or generator expression.

TrivialFix

Change-Id: Ifda9030bb8aa196cb7a5977a57ef46dfefd70fa6
This commit is contained in:
Viktor Varga
2017-08-03 17:39:20 +02:00
committed by Alexander Chadin
parent c4888fee63
commit d218e6f107
2 changed files with 9 additions and 12 deletions

View File

@@ -52,8 +52,8 @@ class AuthTokenMiddleware(auth_token.AuthProtocol):
# The information whether the API call is being performed against the
# public API is required for some other components. Saving it to the
# WSGI environment is reasonable thereby.
env['is_public_api'] = any(map(lambda pattern: re.match(pattern, path),
self.public_api_routes))
env['is_public_api'] = any(re.match(pattern, path)
for pattern in self.public_api_routes)
if env['is_public_api']:
return self._app(env, start_response)

View File

@@ -40,9 +40,8 @@ class CinderHelper(object):
def get_storage_node_by_name(self, name):
"""Get storage node by name(host@backendname)"""
try:
storages = list(filter(lambda storage:
storage.host == name,
self.get_storage_node_list()))
storages = [storage for storage in self.get_storage_node_list()
if storage.host == name]
if len(storages) != 1:
raise exception.StorageNodeNotFound(name=name)
return storages[0]
@@ -56,9 +55,8 @@ class CinderHelper(object):
def get_storage_pool_by_name(self, name):
"""Get pool by name(host@backend#poolname)"""
try:
pools = list(filter(lambda pool:
pool.name == name,
self.get_storage_pool_list()))
pools = [pool for pool in self.get_storage_pool_list()
if pool.name == name]
if len(pools) != 1:
raise exception.PoolNotFound(name=name)
return pools[0]
@@ -75,10 +73,9 @@ class CinderHelper(object):
def get_volume_type_by_backendname(self, backendname):
volume_type_list = self.get_volume_type_list()
volume_type = list(filter(
lambda volume_type:
volume_type.extra_specs.get(
'volume_backend_name') == backendname, volume_type_list))
volume_type = [volume_type for volume_type in volume_type_list
if volume_type.extra_specs.get(
'volume_backend_name') == backendname]
if volume_type:
return volume_type[0].name
else: