[
https://issues.apache.org/jira/browse/LIBCLOUD-763?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14973092#comment-14973092
]
ASF GitHub Bot commented on LIBCLOUD-763:
-----------------------------------------
GitHub user annp89 opened a pull request:
https://github.com/apache/libcloud/pull/613
[LIBCLOUD-763] Simplify str2dicts util function
Reference: https://issues.apache.org/jira/browse/LIBCLOUD-763
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/annp89/libcloud
LIBCLOUD-763_simplify_util_function
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/libcloud/pull/613.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #613
----
commit 6a522438861fce5edf3e0aafe91e6e1bff7e9b79
Author: annp89 <[email protected]>
Date: 2015-10-25T06:37:25Z
[LIBCLOUD-763] Simplify str2dicts util function by using nested list
comprehensions
----
> Making str2dicts util function more pythonic and simpler.
> ---------------------------------------------------------
>
> Key: LIBCLOUD-763
> URL: https://issues.apache.org/jira/browse/LIBCLOUD-763
> Project: Libcloud
> Issue Type: Improvement
> Components: Libcloud REST
> Affects Versions: 0.13.3
> Reporter: Ann Paul
> Priority: Minor
> Labels: improvement, newbie
>
> With reference to the *str2dicts* function here
> https://github.com/apache/libcloud/blob/trunk/libcloud/utils/misc.py#L154
> Two suggestions:
> * I personally think the "\n\n" is not being taken advantage of.
> * Initializing a list and appending a list with empty dict ({}) is not
> necessary and can be removed. This will allow to remove negative indexing on
> the list as well.
> My thoughts are to change it to look like so:
> {code}
> def str2dicts(data):
> if data is not None and data != "":
> data_blocks = data.split("\n\n")
> line_list = [line.rstrip("\n").lstrip("\n").split("\n") for line in
> data_blocks]
> return [dict(key_value_string.split(" ") for key_value_string in
> line) for line in line_list]
> return list({})
> {code}
> Let me know your thoughts on this and when it looks good, i'd be happy to
> open a pull request for with this change.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)