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

bears.python.PyImportSortBear.run()   A

Complexity

Conditions 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 14
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,
10
            filename,
11
            file):
12
        """
13
        Sorts imports for python.
14
        """
15
        new_file = SortImports(
16
            file_contents=''.join(file)).output.splitlines(True)
17
        if new_file != file:
18
            diff = Diff.from_string_arrays(file, new_file)
19
            yield Result(self,
20
                         "Imports can be sorted.",
21
                         affected_code=diff.affected_code(filename),
22
                         diffs={filename: diff})
23