Failed Conditions
Pull Request — master (#1073)
by Lasse
01:41
created

bears.python.PEP8Bear   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %
Metric Value
dl 0
loc 30
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run_autopep() 0 7 1
A run() 0 17 2
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
    RESULT_MESSAGE = "The code does not comply to PEP8."
9
10
    @staticmethod
11
    def run_autopep(file, pep_ignore, pep_select):
12
        new_file = autopep8.fix_code(''.join(file),
13
                                     options={'ignore': pep_ignore,
14
                                              'select': pep_select})
15
16
        return new_file.splitlines(True), []
17
18
    GET_REPLACEMENT = run_autopep
19
20
    def run(self,
21
            filename,
22
            file,
23
            pep_ignore: typed_list(str)=(),
24
            pep_select: typed_list(str)=()):
25
        """
26
        Detects and fixes PEP8 incompliant code. This bear will not change
27
        functionality of the code in any way.
28
29
        :param pep_ignore: A list of errors/warnings to ignore.
30
        :param pep_select: A list of errors/warnings to exclusively apply.
31
        """
32
        for result in self.retrieve_results(filename,
33
                                            file,
34
                                            pep_ignore=pep_ignore,
35
                                            pep_select=pep_select):
36
            yield result
37