Commits

Benjamin Peterson committed 82aeddd

undeprecate the -p option; it's useful for converting python3 sources

Comments (0)

Files changed (3)

     parser.add_option("-l", "--list-fixes", action="store_true",
                       help="List available transformations (fixes/fix_*.py)")
     parser.add_option("-p", "--print-function", action="store_true",
-                      help="DEPRECATED Modify the grammar so that print() is "
-                          "a function")
+                      help="Modify the grammar so that print() is a function")
     parser.add_option("-v", "--verbose", action="store_true",
                       help="More verbose logging")
     parser.add_option("--no-diffs", action="store_true",
 
     # Parse command line arguments
     refactor_stdin = False
+    flags = {}
     options, args = parser.parse_args(args)
     if not options.write and options.no_diffs:
         warn("not writing files and not printing diffs; that's not very useful")
-    if options.print_function:
-        warn("-p is deprecated; "
-             "detection of from __future__ import print_function is automatic")
     if not options.write and options.nobackups:
         parser.error("Can't use -n without -w")
     if options.list_fixes:
         if options.write:
             print >> sys.stderr, "Can't write to stdin."
             return 2
+    if options.print_function:
+        flags["print_function"] = True
 
     # Set up logging handler
     level = logging.DEBUG if options.verbose else logging.INFO
     else:
         requested = avail_fixes.union(explicit)
     fixer_names = requested.difference(unwanted_fixes)
-    rt = StdoutRefactoringTool(sorted(fixer_names), None, sorted(explicit),
+    rt = StdoutRefactoringTool(sorted(fixer_names), flags, sorted(explicit),
                                options.nobackups, not options.no_diffs)
 
     # Refactor all files and directories passed as arguments

lib2to3/refactor.py

 import operator
 import collections
 import StringIO
-import warnings
 from itertools import chain
 
 # Local imports
 
 class RefactoringTool(object):
 
-    _default_options = {}
+    _default_options = {"print_function" : False}
 
     CLASS_PREFIX = "Fix" # The prefix for fixer classes
     FILE_PREFIX = "fix_" # The prefix for modules with a fixer within
         self.explicit = explicit or []
         self.options = self._default_options.copy()
         if options is not None:
-            if "print_function" in options:
-                warnings.warn("the 'print_function' option is deprecated",
-                              DeprecationWarning)
             self.options.update(options)
+        if self.options["print_function"]:
+            self.grammar = pygram.python_grammar_no_print_statement
+        else:
+            self.grammar = pygram.python_grammar
         self.errors = []
         self.logger = logging.getLogger("RefactoringTool")
         self.fixer_log = []
         self.wrote = False
-        self.driver = driver.Driver(pygram.python_grammar,
+        self.driver = driver.Driver(self.grammar,
                                     convert=pytree.convert,
                                     logger=self.logger)
         self.pre_order, self.post_order = self.get_fixers()
                            name, err.__class__.__name__, err)
             return
         finally:
-            self.driver.grammar = pygram.python_grammar
+            self.driver.grammar = self.grammar
         self.log_debug("Refactoring %s", name)
         self.refactor_tree(tree, name)
         return tree

lib2to3/tests/test_refactor.py

         return refactor.RefactoringTool(fixers, options, explicit)
 
     def test_print_function_option(self):
-        with warnings.catch_warnings(record=True) as w:
-            warnings.simplefilter("always", DeprecationWarning)
-            refactor.RefactoringTool(_DEFAULT_FIXERS, {"print_function" : True})
-        self.assertEqual(len(w), 1)
-        msg, = w
-        self.assertTrue(msg.category is DeprecationWarning)
+        rt = self.rt({"print_function" : True})
+        self.assertTrue(rt.grammar is pygram.python_grammar_no_print_statement)
+        self.assertTrue(rt.driver.grammar is
+                        pygram.python_grammar_no_print_statement)
 
     def test_fixer_loading_helpers(self):
         contents = ["explicit", "first", "last", "parrot", "preorder"]