]> granicus.if.org Git - python/commitdiff
Issue #14965: Bring Tools/parser/unparse.py up to date with the Python 3.3. Grammar.
authorMark Dickinson <mdickinson@enthought.com>
Sun, 6 May 2012 16:35:19 +0000 (17:35 +0100)
committerMark Dickinson <mdickinson@enthought.com>
Sun, 6 May 2012 16:35:19 +0000 (17:35 +0100)
1  2 
Misc/NEWS
Tools/parser/test_unparse.py
Tools/parser/unparse.py

diff --cc Misc/NEWS
index b828fda5a3da4c0a7f902fdb243187b628158720,37f2209d939b764cae45455c49a45dd7ca8581e9..3af54fa57789e4d51447ce26050fa26b3342b51f
+++ b/Misc/NEWS
@@@ -2,37 -2,10 +2,43 @@@
  Python News
  +++++++++++
  
 -What's New in Python 3.2.4
 -==========================
 +What's New in Python 3.3.0 Alpha 4?
 +===================================
  
 -*Release date: XX-XX-XXXX*
 +*Release date: XX-XXX-2012*
 +
 +Core and Builtins
 +-----------------
 +
 +- Issue #14705: The PyArg_Parse() family of functions now support the 'p' format
 +  unit, which accepts a "boolean predicate" argument.  It converts any Python
 +  value into an integer--0 if it is "false", and 1 otherwise.
 +
 +Library
 +-------
 +
 +- Issue #13989: Add support for text mode to gzip.open().
 +
 +- Issue #14127: The os.stat() result object now provides three additional
 +  fields: st_ctime_ns, st_mtime_ns, and st_atime_ns, providing those times as an
 +  integer with nanosecond resolution.  The functions os.utime(), os.lutimes(),
 +  and os.futimes() now accept a new parameter, ns, which accepts mtime and atime
 +  as integers with nanosecond resolution.
 +
 +- Issue #14127 and #10148: shutil.copystat now preserves exact mtime and atime
 +  on filesystems providing nanosecond resolution.
 +
++Tools/Demos
++-----------
++
++- Issue #14965: Bring Tools/parser/unparse.py support up to date with
++  the Python 3.3 Grammar.
++
 +
 +What's New in Python 3.3.0 Alpha 3?
 +===================================
 +
 +*Release date: 01-May-2012*
  
  Core and Builtins
  -----------------
index d457523b7c2d13f9970c975aba30e42ece8409e2,2ac1ea670fe79e552d9c0aad6fdbf3e723e1bf7d..647366c93d1cbbe0128f04ee228b1fb3e2ee5d82
@@@ -93,6 -93,6 +93,21 @@@ finally
      suite5
  """
  
++with_simple = """\
++with f():
++    suite1
++"""
++
++with_as = """\
++with f() as x:
++    suite1
++"""
++
++with_two_items = """\
++with f() as x, g() as y:
++    suite1
++"""
++
  class ASTTestCase(unittest.TestCase):
      def assertASTEqual(self, ast1, ast2):
          self.assertEqual(ast.dump(ast1), ast.dump(ast2))
@@@ -209,6 -209,13 +224,22 @@@ class UnparseTestCase(ASTTestCase)
      def test_try_except_finally(self):
          self.check_roundtrip(try_except_finally)
  
+     def test_starred_assignment(self):
+         self.check_roundtrip("a, *b, c = seq")
+         self.check_roundtrip("a, (*b, c) = seq")
+         self.check_roundtrip("a, *b[0], c = seq")
+         self.check_roundtrip("a, *(b, c) = seq")
++    def test_with_simple(self):
++        self.check_roundtrip(with_simple)
++
++    def test_with_as(self):
++        self.check_roundtrip(with_as)
++
++    def test_with_two_items(self):
++        self.check_roundtrip(with_two_items)
++
  class DirectoryTestCase(ASTTestCase):
      """Test roundtrip behaviour on all files in Lib and Lib/test."""
  
index e96ef5477b872ae9e11b83ef95e4da71761ed5d7,d9fca975c589c3da7a6788588f150bf18f5a6e86..9ae5b469490f0970ab39510e918a71642fe322b7
@@@ -147,6 -147,6 +147,14 @@@ class Unparser
              self.dispatch(t.value)
          self.write(")")
  
++    def _YieldFrom(self, t):
++        self.write("(")
++        self.write("yield from")
++        if t.value:
++            self.write(" ")
++            self.dispatch(t.value)
++        self.write(")")
++
      def _Raise(self, t):
          self.fill("raise")
          if not t.exc:
              self.write(" from ")
              self.dispatch(t.cause)
  
--    def _TryExcept(self, t):
++    def _Try(self, t):
          self.fill("try")
          self.enter()
          self.dispatch(t.body)
          self.leave()
--
          for ex in t.handlers:
              self.dispatch(ex)
          if t.orelse:
              self.enter()
              self.dispatch(t.orelse)
              self.leave()
--
--    def _TryFinally(self, t):
--        if len(t.body) == 1 and isinstance(t.body[0], ast.TryExcept):
--            # try-except-finally
--            self.dispatch(t.body)
--        else:
--            self.fill("try")
++        if t.finalbody:
++            self.fill("finally")
              self.enter()
--            self.dispatch(t.body)
++            self.dispatch(t.finalbody)
              self.leave()
  
--        self.fill("finally")
--        self.enter()
--        self.dispatch(t.finalbody)
--        self.leave()
--
      def _ExceptHandler(self, t):
          self.fill("except")
          if t.type:
  
      def _With(self, t):
          self.fill("with ")
--        self.dispatch(t.context_expr)
--        if t.optional_vars:
--            self.write(" as ")
--            self.dispatch(t.optional_vars)
++        interleave(lambda: self.write(", "), self.dispatch, t.items)
          self.enter()
          self.dispatch(t.body)
          self.leave()
          if t.asname:
              self.write(" as "+t.asname)
  
++    def _withitem(self, t):
++        self.dispatch(t.context_expr)
++        if t.optional_vars:
++            self.write(" as ")
++            self.dispatch(t.optional_vars)
++
  def roundtrip(filename, output=sys.stdout):
      with open(filename, "rb") as pyfile:
          encoding = tokenize.detect_encoding(pyfile.readline)[0]