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

bears.python.PyImportSortBear   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %
Metric Value
dl 0
loc 16
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 2
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(
20
                self,
21
                "Imports can be sorted.",
22
                affected_code=diff.affected_code(filename),
23
                diffs={filename: diff})
24