Completed
Pull Request — master (#1073)
by Lasse
01:56
created

bears.Python.PEP8Bear.run_autopep()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 7
rs 9.4286
1
import autopep8
2
3
from bears.linters.CorrectionBasedBear import CorrectionBasedBear
4
from coalib.settings.Setting import typed_list
5
6
7
class PEP8Bear(CorrectionBasedBear):
8
    GET_REPLACEMENT = lambda self, **kwargs: self.run_autopep(**kwargs)
9
    RESULT_MESSAGE = "The code does not comply to PEP8."
10
11
    @staticmethod
12
    def run_autopep(file, pep_ignore, pep_select):
13
        new_file = autopep8.fix_code(''.join(file),
14
                                     options={'ignore': pep_ignore,
15
                                              'select': pep_select})
16
17
        return new_file.splitlines(True), []
18
19
    def run(self,
20
            filename,
21
            file,
22
            pep_ignore: typed_list(str)=(),
23
            pep_select: typed_list(str)=()):
24
        """
25
        Detects and fixes PEP8 incompliant code. This bear will not change
26
        functionality of the code in any way.
27
28
        :param pep_ignore: A list of errors/warnings to ignore.
29
        :param pep_select: A list of errors/warnings to exclusively apply.
30
        """
31
        for result in self.retrieve_results(filename,
32
                                            file,
33
                                            pep_ignore=pep_ignore,
34
                                            pep_select=pep_select):
35
            yield result
36