bpo-39313: Add an option to RefactoringTool for using exec as a function (GH-17967)

https://bugs.python.org/issue39313


Automerge-Triggered-By: @pablogsal
This commit is contained in:
Batuhan Taşkaya 2020-01-13 01:13:31 +03:00 committed by Miss Islington (bot)
parent 14dbe4b3f0
commit 61b14151cc
5 changed files with 23 additions and 8 deletions

View file

@ -155,6 +155,7 @@ class FixerError(Exception):
class RefactoringTool(object):
_default_options = {"print_function" : False,
"exec_function": False,
"write_unchanged_files" : False}
CLASS_PREFIX = "Fix" # The prefix for fixer classes
@ -173,10 +174,13 @@ class RefactoringTool(object):
self.options = self._default_options.copy()
if options is not None:
self.options.update(options)
if self.options["print_function"]:
self.grammar = pygram.python_grammar_no_print_statement
else:
self.grammar = pygram.python_grammar
self.grammar = pygram.python_grammar.copy()
if self.options['print_function']:
del self.grammar.keywords["print"]
elif self.options['exec_function']:
del self.grammar.keywords["exec"]
# When this is True, the refactor*() methods will call write_file() for
# files processed even if they were not changed during refactoring. If
# and only if the refactor method's write parameter was True.