1. Joe Amenta
  2. lib3to2

Commits

Joe Amenta  committed 028b96d

Adding "from __future__ import with_statement"

  • Participants
  • Parent commits 763e8d9
  • Branches default

Comments (0)

Files changed (2)

File lib3to2/fixes/fix_with.py

View file
+"""
+Fixer for from __future__ import with_statement
+"""
+
+from lib2to3 import fixer_base
+from ..fixer_util import future_import
+
+class FixWith(fixer_base.BaseFix):
+
+    PATTERN = "with_stmt"
+
+    def transform(self, node, results):
+        future_import("with_statement", node)

File lib3to2/tests/test_with.py

View file
+from test_all_fixers import lib3to2FixerTestCase
+
+class Test_with(lib3to2FixerTestCase):
+    fixer = "with"
+
+    def test_with_oneline(self):
+        b = "with a as b: pass"
+        a = "from __future__ import with_statement\nwith a as b: pass"
+        self.check(b, a)
+
+    def test_with_suite(self):
+        b = "with a as b:\n    pass"
+        a = "from __future__ import with_statement\nwith a as b:\n    pass"
+        self.check(b, a)