| Total Complexity | 4 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| 1 | import autopep8 |
||
| 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 |