STINNER Victor <[EMAIL PROTECTED]> added the comment:

Le Friday 03 October 2008 04:44:13 Benjamin Peterson, vous avez écrit :
> You're patch looks pretty good. Could you write tests for it, though?

My patch doesn't work, that's why I don't write unit test :-)
 - os.getcwdu() was correctly replaced
 - getcwdu() was also replaced
 - but not "from os import getcwdu"

Since most people use os.getcwdu(), and that 2to3 is unable to make sure that 
getcwdu() comes from os or is an user defined module, I prefer to only keep 
the first fixer (os.getcwdu() => os.getcwd()). The new patch include a test.

(Let's try Roundup by email using an attachment :-))

Added file: http://bugs.python.org/file11691/fix_getcwdu-2.patch

_______________________________________
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue4023>
_______________________________________
Index: Lib/lib2to3/fixes/fix_getcwdu.py
===================================================================
--- Lib/lib2to3/fixes/fix_getcwdu.py    (révision 0)
+++ Lib/lib2to3/fixes/fix_getcwdu.py    (révision 0)
@@ -0,0 +1,19 @@
+"""
+Fixer that changes os.getcwdu() to os.getcwd().
+"""
+# Author: Victor Stinner
+
+# Local imports
+from .. import fixer_base
+from ..fixer_util import Name
+
+class FixGetcwdu(fixer_base.BaseFix):
+
+    PATTERN = """
+              power< 'os' trailer< dot='.' name='getcwdu' > trailer< '(' [any] 
')' > >
+              """
+
+    def transform(self, node, results):
+        name = results["name"]
+        name.replace(Name("getcwd", prefix=name.get_prefix()))
+

Modification de propriétés sur Lib/lib2to3/fixes/fix_getcwdu.py
___________________________________________________________________
Nom : svn:eol-style
   + native

Index: Lib/lib2to3/tests/test_fixers.py
===================================================================
--- Lib/lib2to3/tests/test_fixers.py    (révision 66750)
+++ Lib/lib2to3/tests/test_fixers.py    (copie de travail)
@@ -3576,7 +3576,20 @@
         a = """class m(a, arg=23, metaclass=Meta): pass"""
         self.check(b, a)
 
+class Test_getcwdu(FixerTestCase):
 
+    fixer = 'getcwdu'
+
+    def test_import(self):
+        b = """import os
+cwd = os.getcwdu()
+print "cwd=%s" % cwd"""
+        a = """import os
+cwd = os.getcwd()
+print "cwd=%s" % cwd"""
+        self.check(b, a)
+
+
 if __name__ == "__main__":
     import __main__
     support.run_all_tests(__main__)
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to