diff options
Diffstat (limited to 'pylint/lint.py')
-rw-r--r-- | pylint/lint.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/pylint/lint.py b/pylint/lint.py index eb8f706..4dfb87c 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -406,6 +406,19 @@ class PyLinter(configuration.OptionsManagerMixIn, ' loading into the active Python interpreter and may run' ' arbitrary code')} ), + + ('optimize-ast', + {'type': 'yn', 'metavar': '<yn>', 'default': False, + 'help': ('Allow optimization of some AST trees. This will ' + 'activate a peephole AST optimizer, which will ' + 'apply various small optimizations. For instance, ' + 'it can be used to obtain the result of joining ' + 'multiple strings with the addition operator. ' + 'Joining a lot of strings can lead to a maximum ' + 'recursion error in Pylint and this flag can prevent ' + 'that. It has one side effect, the resulting AST ' + 'will be different than the one from reality.')} + ), ) option_groups = ( @@ -895,10 +908,14 @@ class PyLinter(configuration.OptionsManagerMixIn, """return a ast(roid) representation for a module""" try: return MANAGER.ast_from_file(filepath, modname, source=True) - except SyntaxError as ex: - self.add_message('syntax-error', line=ex.lineno, args=ex.msg) except astroid.AstroidBuildingException as ex: - self.add_message('parse-error', args=ex) + if isinstance(ex.args[0], SyntaxError): + ex = ex.args[0] + self.add_message('syntax-error', + line=ex.lineno, + args=ex.msg) + else: + self.add_message('parse-error', args=ex) except Exception as ex: # pylint: disable=broad-except import traceback traceback.print_exc() @@ -940,6 +957,7 @@ class PyLinter(configuration.OptionsManagerMixIn, self.stats = {'by_module' : {}, 'by_msg' : {}, } + MANAGER.optimize_ast = self.config.optimize_ast MANAGER.always_load_extensions = self.config.unsafe_load_any_extension MANAGER.extension_package_whitelist.update( self.config.extension_pkg_whitelist) |