Completed
Pull Request — master (#1152)
by Lasse
01:50
created

bears.python.PyImportSortBear.run()   A

Complexity

Conditions 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 12
rs 9.4286
1
from isort import SortImports
2
3
from coalib.bears.LocalBear import LocalBear
4
from coalib.results.Diff import Diff
5
from coalib.results.Result import Result
6
7
8
class PyImportSortBear(LocalBear):
9
    def run(self, filename, file):
10
        """
11
        Sorts imports for python.
12
        """
13
        new_file = SortImports(
14
            file_contents=''.join(file)).output.splitlines(True)
15
        if new_file != file:
16
            diff = Diff.from_string_arrays(file, new_file)
17
            yield Result(self,
18
                         "Imports can be sorted.",
19
                         affected_code=diff.affected_code(filename),
20
                         diffs={filename: diff})
21