Joe Amenta avatar Joe Amenta committed 028b96d

Adding "from __future__ import with_statement"

Comments (0)

Files changed (2)

lib3to2/fixes/fix_with.py

+"""
+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)

lib3to2/tests/test_with.py

+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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.