diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2015-08-24 00:09:37 -0700 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2015-08-24 00:09:37 -0700 |
commit | cb23c9f0ae729b20724fb0c4467a7017e6a0b440 (patch) | |
tree | 5f294fa766b77a02377f394125bd762e76a6179e | |
parent | ac83f3cbd5b0c9761f36300298b86729b3b88f33 (diff) | |
download | isort-cb23c9f0ae729b20724fb0c4467a7017e6a0b440.tar.gz |
Ensure a commant can't accidentily get added twicefeature/fix-issue-303
-rw-r--r-- | isort/isort.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/isort/isort.py b/isort/isort.py index d7cb9b36..bfaed295 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -332,7 +332,7 @@ class SortImports(object): else: import_definition = "import {0}".format(module) - comments_above = self.comments['above']['straight'].get(module, None) + comments_above = self.comments['above']['straight'].pop(module, None) if comments_above: section_output.append(comments_above) section_output.append(self._add_comments(self.comments['straight'].get(module), import_definition)) @@ -365,14 +365,14 @@ class SortImports(object): from_imports.remove(from_import) if from_imports: - comments = self.comments['from'].get(module) + comments = self.comments['from'].pop(module, ()) if "*" in from_imports and self.config['combine_star']: import_statement = self._wrap(self._add_comments(comments, "{0}*".format(import_start))) elif self.config['force_single_line']: import_statements = [] for from_import in from_imports: single_import_line = self._add_comments(comments, import_start + from_import) - comment = self.comments['nested'].get(module, {}).get(from_import, None) + comment = self.comments['nested'].get(module, {}).pop(from_import, None) if comment: single_import_line += "{0} {1}".format(comments and ";" or " #", comment) import_statements.append(self._wrap(single_import_line)) @@ -387,11 +387,11 @@ class SortImports(object): comments = None for from_import in copy.copy(from_imports): - comment = self.comments['nested'].get(module, {}).get(from_import, None) + comment = self.comments['nested'].get(module, {}).pop(from_import, None) if comment: single_import_line = self._add_comments(comments, import_start + from_import) single_import_line += "{0} {1}".format(comments and ";" or " #", comment) - above_comments = self.comments['above']['from'].get(module, None) + above_comments = self.comments['above']['from'].pop(module, None) if above_comments: section_output.extend(above_comments) section_output.append(self._wrap(single_import_line)) @@ -435,7 +435,7 @@ class SortImports(object): import_statement = self._wrap(import_statement) if import_statement: - above_comments = self.comments['above']['from'].get(module, None) + above_comments = self.comments['above']['from'].pop(module, None) if above_comments: section_output.extend(above_comments) section_output.append(import_statement) |