diff options
author | Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com> | 2020-01-13 01:13:31 +0300 |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-01-12 14:13:31 -0800 |
commit | 61b14151cc92021a10f94765eaa152ed04eb262a (patch) | |
tree | be6f59fe41c8da9aa600ebe006701a640c5a2a85 /Lib/lib2to3/refactor.py | |
parent | 14dbe4b3f0a888a60e8cc20f3df5aa09c8bb82c3 (diff) | |
download | cpython-git-61b14151cc92021a10f94765eaa152ed04eb262a.tar.gz |
bpo-39313: Add an option to RefactoringTool for using exec as a function (GH-17967)
https://bugs.python.org/issue39313
Automerge-Triggered-By: @pablogsal
Diffstat (limited to 'Lib/lib2to3/refactor.py')
-rw-r--r-- | Lib/lib2to3/refactor.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py index 55fd60fa27..3a5aafffc6 100644 --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -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. |