50 900 syntax error |
50 900 syntax error |
51 """ |
51 """ |
52 |
52 |
53 # |
53 # |
54 # This is a modified version to make the original pycodestyle.py better |
54 # This is a modified version to make the original pycodestyle.py better |
55 # suitable for being called from within the eric6 IDE. The modifications |
55 # suitable for being called from within the eric IDE. The modifications |
56 # are as follows: |
56 # are as follows: |
57 # |
57 # |
58 # - made messages translatable via Qt |
58 # - made messages translatable via Qt |
59 # - added code for eric6 integration |
59 # - added code for eric integration |
60 # |
60 # |
61 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
61 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
62 # |
62 # |
63 |
63 |
64 import inspect |
64 import inspect |
2014 self.report = report or options.report |
2014 self.report = report or options.report |
2015 self.report_error = self.report.error |
2015 self.report_error = self.report.error |
2016 self.report_error_args = self.report.error_args |
2016 self.report_error_args = self.report.error_args |
2017 self.noqa = False |
2017 self.noqa = False |
2018 |
2018 |
2019 # added for eric6 integration |
2019 # added for eric integration |
2020 self.options = options |
2020 self.options = options |
2021 |
2021 |
2022 def report_invalid_syntax(self): |
2022 def report_invalid_syntax(self): |
2023 """Check if the syntax is valid.""" |
2023 """Check if the syntax is valid.""" |
2024 (exc_type, exc) = sys.exc_info()[:2] |
2024 (exc_type, exc) = sys.exc_info()[:2] |
2144 try: |
2144 try: |
2145 tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) |
2145 tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) |
2146 except (ValueError, SyntaxError, TypeError): |
2146 except (ValueError, SyntaxError, TypeError): |
2147 return self.report_invalid_syntax() |
2147 return self.report_invalid_syntax() |
2148 for name, cls, __ in self._ast_checks: |
2148 for name, cls, __ in self._ast_checks: |
2149 # extended API for eric6 integration |
2149 # extended API for eric integration |
2150 checker = cls(tree, self.filename, self.options) |
2150 checker = cls(tree, self.filename, self.options) |
2151 for args in checker.run(): |
2151 for args in checker.run(): |
2152 lineno = args[0] |
2152 lineno = args[0] |
2153 if not self.lines or not noqa(self.lines[lineno - 1]): |
2153 if not self.lines or not noqa(self.lines[lineno - 1]): |
2154 self.report_error_args(lineno, *args[1:]) |
2154 self.report_error_args(lineno, *args[1:]) |