[Python-checkins] r53977 - in python/branches/twouters-dictviews-backport: Include/code.h Include/compile.h Include/pythonrun.h Lib/__future__.py Lib/compiler/consts.py Lib/compiler/future.py Lib/compiler/pycodegen.py Lib/test/test_compiler.py Lib/test/test_dict.py Lib/test/test_dictviews.py Python/bltinmodule.c Python/compile.c Python/future.c

thomas.wouters python-checkins at python.org
Tue Feb 27 01:10:28 CET 2007


Author: thomas.wouters
Date: Tue Feb 27 01:10:25 2007
New Revision: 53977

Added:
   python/branches/twouters-dictviews-backport/Lib/test/test_dictviews.py
      - copied, changed from r53969, python/branches/p3yk/Lib/test/test_dictviews.py
Modified:
   python/branches/twouters-dictviews-backport/Include/code.h
   python/branches/twouters-dictviews-backport/Include/compile.h
   python/branches/twouters-dictviews-backport/Include/pythonrun.h
   python/branches/twouters-dictviews-backport/Lib/__future__.py
   python/branches/twouters-dictviews-backport/Lib/compiler/consts.py
   python/branches/twouters-dictviews-backport/Lib/compiler/future.py
   python/branches/twouters-dictviews-backport/Lib/compiler/pycodegen.py
   python/branches/twouters-dictviews-backport/Lib/test/test_compiler.py
   python/branches/twouters-dictviews-backport/Lib/test/test_dict.py
   python/branches/twouters-dictviews-backport/Python/bltinmodule.c
   python/branches/twouters-dictviews-backport/Python/compile.c
   python/branches/twouters-dictviews-backport/Python/future.c
Log:

Rename the 'dictviews' future-import into 'dict_views' as Guido requested.
Also copy test_dictviews from p3yk (but adjust for the lack of set
literals.)



Modified: python/branches/twouters-dictviews-backport/Include/code.h
==============================================================================
--- python/branches/twouters-dictviews-backport/Include/code.h	(original)
+++ python/branches/twouters-dictviews-backport/Include/code.h	Tue Feb 27 01:10:25 2007
@@ -48,7 +48,7 @@
 #define CO_FUTURE_DIVISION    	0x2000
 #define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */
 #define CO_FUTURE_WITH_STATEMENT  0x8000
-#define CO_FUTURE_DICTVIEWS	0x10000
+#define CO_FUTURE_DICT_VIEWS	0x10000
 
 /* This should be defined if a future statement modifies the syntax.
    For example, when a keyword is added.

Modified: python/branches/twouters-dictviews-backport/Include/compile.h
==============================================================================
--- python/branches/twouters-dictviews-backport/Include/compile.h	(original)
+++ python/branches/twouters-dictviews-backport/Include/compile.h	Tue Feb 27 01:10:25 2007
@@ -24,7 +24,7 @@
 #define FUTURE_DIVISION "division"
 #define FUTURE_ABSOLUTE_IMPORT "absolute_import"
 #define FUTURE_WITH_STATEMENT "with_statement"
-#define FUTURE_DICTVIEWS "dictviews"
+#define FUTURE_DICT_VIEWS "dict_views"
 
 struct _mod; /* Declare the existence of this type */
 PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,

Modified: python/branches/twouters-dictviews-backport/Include/pythonrun.h
==============================================================================
--- python/branches/twouters-dictviews-backport/Include/pythonrun.h	(original)
+++ python/branches/twouters-dictviews-backport/Include/pythonrun.h	Tue Feb 27 01:10:25 2007
@@ -8,7 +8,7 @@
 #endif
 
 #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
-                   CO_FUTURE_WITH_STATEMENT | CO_FUTURE_DICTVIEWS)
+                   CO_FUTURE_WITH_STATEMENT | CO_FUTURE_DICT_VIEWS)
 #define PyCF_MASK_OBSOLETE (CO_NESTED)
 #define PyCF_SOURCE_IS_UTF8  0x0100
 #define PyCF_DONT_IMPLY_DEDENT 0x0200

Modified: python/branches/twouters-dictviews-backport/Lib/__future__.py
==============================================================================
--- python/branches/twouters-dictviews-backport/Lib/__future__.py	(original)
+++ python/branches/twouters-dictviews-backport/Lib/__future__.py	Tue Feb 27 01:10:25 2007
@@ -53,7 +53,7 @@
     "division",
     "absolute_import",
     "with_statement",
-    "dictviews",
+    "dict_views",
 ]
 
 __all__ = ["all_feature_names"] + all_feature_names
@@ -67,7 +67,7 @@
 CO_FUTURE_DIVISION   = 0x2000   # division
 CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
 CO_FUTURE_WITH_STATEMENT  = 0x8000   # with statement
-CO_FUTURE_DICTVIEWS  = 0x10000
+CO_FUTURE_DICT_VIEWS  = 0x10000
 
 class _Feature:
     def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
@@ -117,6 +117,6 @@
                           (2, 6, 0, "alpha", 0),
                           CO_FUTURE_WITH_STATEMENT)
 
-dictviews = _Feature((2, 6, 0, "alpha", 1),
-                     (3, 0, 0, "alpha", 0),
-                     CO_FUTURE_DICTVIEWS)
+dict_views = _Feature((2, 6, 0, "alpha", 1),
+                      (3, 0, 0, "alpha", 0),
+                      CO_FUTURE_DICT_VIEWS)

Modified: python/branches/twouters-dictviews-backport/Lib/compiler/consts.py
==============================================================================
--- python/branches/twouters-dictviews-backport/Lib/compiler/consts.py	(original)
+++ python/branches/twouters-dictviews-backport/Lib/compiler/consts.py	Tue Feb 27 01:10:25 2007
@@ -19,4 +19,4 @@
 CO_FUTURE_DIVISION = 0x2000
 CO_FUTURE_ABSIMPORT = 0x4000
 CO_FUTURE_WITH_STATEMENT = 0x8000
-CO_FUTURE_DICTVIEWS = 0x10000
+CO_FUTURE_DICT_VIEWS = 0x10000

Modified: python/branches/twouters-dictviews-backport/Lib/compiler/future.py
==============================================================================
--- python/branches/twouters-dictviews-backport/Lib/compiler/future.py	(original)
+++ python/branches/twouters-dictviews-backport/Lib/compiler/future.py	Tue Feb 27 01:10:25 2007
@@ -16,7 +16,7 @@
 class FutureParser:
 
     features = ("nested_scopes", "generators", "division",
-                "absolute_import", "with_statement", "dictviews")
+                "absolute_import", "with_statement", "dict_views")
 
     def __init__(self):
         self.found = {} # set

Modified: python/branches/twouters-dictviews-backport/Lib/compiler/pycodegen.py
==============================================================================
--- python/branches/twouters-dictviews-backport/Lib/compiler/pycodegen.py	(original)
+++ python/branches/twouters-dictviews-backport/Lib/compiler/pycodegen.py	Tue Feb 27 01:10:25 2007
@@ -10,7 +10,7 @@
 from compiler.consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL
 from compiler.consts import (CO_VARARGS, CO_VARKEYWORDS, CO_NEWLOCALS,
      CO_NESTED, CO_GENERATOR, CO_FUTURE_DIVISION,
-     CO_FUTURE_ABSIMPORT, CO_FUTURE_WITH_STATEMENT, CO_FUTURE_DICTVIEWS)
+     CO_FUTURE_ABSIMPORT, CO_FUTURE_WITH_STATEMENT, CO_FUTURE_DICT_VIEWS)
 from compiler.pyassem import TupleArg
 
 # XXX The version-specific code can go, since this code only works with 2.x.
@@ -218,8 +218,8 @@
                 self.graph.setFlag(CO_FUTURE_ABSIMPORT)
             elif feature == "with_statement":
                 self.graph.setFlag(CO_FUTURE_WITH_STATEMENT)
-            elif feature == "dictviews":
-                self.graph.setFlag(CO_FUTURE_DICTVIEWS)
+            elif feature == "dict_views":
+                self.graph.setFlag(CO_FUTURE_DICT_VIEWS)
 
     def initClass(self):
         """This method is called once for each class"""
@@ -932,7 +932,7 @@
             self.emit('LOAD_ATTR', elt)
 
     def _checkViewAttr(self, regop, viewop, attrname):
-        if (self.graph.checkFlag(CO_FUTURE_DICTVIEWS) and
+        if (self.graph.checkFlag(CO_FUTURE_DICT_VIEWS) and
             attrname in ('keys', 'items', 'values')):
             return viewop
         else:

Modified: python/branches/twouters-dictviews-backport/Lib/test/test_compiler.py
==============================================================================
--- python/branches/twouters-dictviews-backport/Lib/test/test_compiler.py	(original)
+++ python/branches/twouters-dictviews-backport/Lib/test/test_compiler.py	Tue Feb 27 01:10:25 2007
@@ -163,7 +163,7 @@
             def viewkeys(self): pass
             def viewitems(self): pass
             def viewvalues(self): pass
-        c = compiler.compile('from __future__ import dictviews\n'
+        c = compiler.compile('from __future__ import dict_views\n'
                              'keys, items, values = d.keys, d.items, d.values\n',
                              '<string>',
                              'exec')

Modified: python/branches/twouters-dictviews-backport/Lib/test/test_dict.py
==============================================================================
--- python/branches/twouters-dictviews-backport/Lib/test/test_dict.py	(original)
+++ python/branches/twouters-dictviews-backport/Lib/test/test_dict.py	Tue Feb 27 01:10:25 2007
@@ -491,7 +491,7 @@
         else:
             self.fail("missing KeyError")
 
-    def test_dictviews_future(self):
+    def test_dict_views_future(self):
         import __future__
 
         d = {'a': 1, 'b': 2, 'c': 3}
@@ -505,15 +505,15 @@
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.values.__name__)
         c = compile("d.keys", "d.keys", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.viewkeys.__name__)
         c = compile("d.items", "d.items", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.viewitems.__name__)
         c = compile("d.values", "d.values", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.viewvalues.__name__)
 
@@ -528,15 +528,15 @@
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.values.__name__)
         c = compile("d.keys", "d.keys", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.viewkeys.__name__)
         c = compile("d.items", "d.items", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.viewitems.__name__)
         c = compile("d.values", "d.values", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.viewvalues.__name__)
 
@@ -562,15 +562,15 @@
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.values.__name__)
         c = compile("d.keys", "d.keys", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.keys.__name__)
         c = compile("d.items", "d.items", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.items.__name__)
         c = compile("d.values", "d.values", "eval",
-                    __future__.CO_FUTURE_DICTVIEWS)
+                    __future__.CO_FUTURE_DICT_VIEWS)
         k = eval(c, locals())
         self.assertEquals(k.__name__, d.values.__name__)
 

Copied: python/branches/twouters-dictviews-backport/Lib/test/test_dictviews.py (from r53969, python/branches/p3yk/Lib/test/test_dictviews.py)
==============================================================================
--- python/branches/p3yk/Lib/test/test_dictviews.py	(original)
+++ python/branches/twouters-dictviews-backport/Lib/test/test_dictviews.py	Tue Feb 27 01:10:25 2007
@@ -1,3 +1,4 @@
+from __future__ import dict_views
 import unittest
 from test import test_support
 
@@ -18,11 +19,11 @@
         d = {1: 10, "a": "ABC"}
         keys = d.keys()
         self.assertEqual(len(keys), 2)
-        self.assertEqual(set(keys), {1, "a"})
-        self.assertEqual(keys, {1, "a"})
-        self.assertNotEqual(keys, {1, "a", "b"})
-        self.assertNotEqual(keys, {1, "b"})
-        self.assertNotEqual(keys, {1})
+        self.assertEqual(set(keys), set([1, "a"]))
+        self.assertEqual(keys, set([1, "a"]))
+        self.assertNotEqual(keys, set([1, "a", "b"]))
+        self.assertNotEqual(keys, set([1, "b"]))
+        self.assertNotEqual(keys, set([1]))
         self.assertNotEqual(keys, 42)
         self.assert_(1 in keys)
         self.assert_("a" in keys)
@@ -38,11 +39,11 @@
         d = {1: 10, "a": "ABC"}
         items = d.items()
         self.assertEqual(len(items), 2)
-        self.assertEqual(set(items), {(1, 10), ("a", "ABC")})
-        self.assertEqual(items, {(1, 10), ("a", "ABC")})
-        self.assertNotEqual(items, {(1, 10), ("a", "ABC"), "junk"})
-        self.assertNotEqual(items, {(1, 10), ("a", "def")})
-        self.assertNotEqual(items, {(1, 10)})
+        self.assertEqual(set(items), set([(1, 10), ("a", "ABC")]))
+        self.assertEqual(items, set([(1, 10), ("a", "ABC")]))
+        self.assertNotEqual(items, set([(1, 10), ("a", "ABC"), "junk"]))
+        self.assertNotEqual(items, set([(1, 10), ("a", "def")]))
+        self.assertNotEqual(items, set([(1, 10)]))
         self.assertNotEqual(items, 42)
         self.assert_((1, 10) in items)
         self.assert_(("a", "ABC") in items)
@@ -66,7 +67,7 @@
     def test_dict_values(self):
         d = {1: 10, "a": "ABC"}
         values = d.values()
-        self.assertEqual(set(values), {10, "ABC"})
+        self.assertEqual(set(values), set([10, "ABC"]))
         self.assertEqual(len(values), 2)
 
 def test_main():

Modified: python/branches/twouters-dictviews-backport/Python/bltinmodule.c
==============================================================================
--- python/branches/twouters-dictviews-backport/Python/bltinmodule.c	(original)
+++ python/branches/twouters-dictviews-backport/Python/bltinmodule.c	Tue Feb 27 01:10:25 2007
@@ -742,7 +742,7 @@
 	     strcmp(sname, "items") == 0 ||
 	     strcmp(sname, "values") == 0) &&
 	    (PyThreadState_GET()->frame->f_code->co_flags & 
-	    					CO_FUTURE_DICTVIEWS)) {
+	    					CO_FUTURE_DICT_VIEWS)) {
 	    	result = _PyObject_GetViewAttr(v, name);
 	} else
 		result = PyObject_GetAttr(v, name);
@@ -1029,7 +1029,7 @@
 	     strcmp(sname, "items") == 0 ||
 	     strcmp(sname, "values") == 0) &&
 	    (PyThreadState_GET()->frame->f_code->co_flags & 
-	    					CO_FUTURE_DICTVIEWS)) {
+	    					CO_FUTURE_DICT_VIEWS)) {
 	    	result = _PyObject_SetViewAttr(v, name, value);
 	} else
 		result = PyObject_SetAttr(v, name, value);
@@ -1075,7 +1075,7 @@
 	     strcmp(sname, "items") == 0 ||
 	     strcmp(sname, "values") == 0) &&
 	    (PyThreadState_GET()->frame->f_code->co_flags & 
-	    					CO_FUTURE_DICTVIEWS)) {
+	    					CO_FUTURE_DICT_VIEWS)) {
 	    	result = _PyObject_SetViewAttr(v, name, (PyObject *)NULL);
 	} else
 		result = PyObject_SetAttr(v, name, (PyObject *)NULL);

Modified: python/branches/twouters-dictviews-backport/Python/compile.c
==============================================================================
--- python/branches/twouters-dictviews-backport/Python/compile.c	(original)
+++ python/branches/twouters-dictviews-backport/Python/compile.c	Tue Feb 27 01:10:25 2007
@@ -3032,13 +3032,13 @@
 	return 1;
 }
 
-	/* Helper to handle dictviews future-import magic */
+	/* Helper to handle dict views future-import magic */
 static int
 compiler_attrop(struct compiler *c, expr_ty e)
 {
 	int needviews = 0;
 	
-	if (c->c_flags && (c->c_flags->cf_flags & CO_FUTURE_DICTVIEWS)) {
+	if (c->c_flags && (c->c_flags->cf_flags & CO_FUTURE_DICT_VIEWS)) {
 		const char *attrstr = PyString_AS_STRING(e->v.Attribute.attr);
 		if (strcmp(attrstr, "keys") == 0 ||
 		    strcmp(attrstr, "items") == 0 ||

Modified: python/branches/twouters-dictviews-backport/Python/future.c
==============================================================================
--- python/branches/twouters-dictviews-backport/Python/future.c	(original)
+++ python/branches/twouters-dictviews-backport/Python/future.c	Tue Feb 27 01:10:25 2007
@@ -33,8 +33,8 @@
 			ff->ff_features |= CO_FUTURE_ABSOLUTE_IMPORT;
 		} else if (strcmp(feature, FUTURE_WITH_STATEMENT) == 0) {
 			ff->ff_features |= CO_FUTURE_WITH_STATEMENT;
-		} else if (strcmp(feature, FUTURE_DICTVIEWS) == 0) {
-			ff->ff_features |= CO_FUTURE_DICTVIEWS;
+		} else if (strcmp(feature, FUTURE_DICT_VIEWS) == 0) {
+			ff->ff_features |= CO_FUTURE_DICT_VIEWS;
 		} else if (strcmp(feature, "braces") == 0) {
 			PyErr_SetString(PyExc_SyntaxError,
 					"not a chance");


More information about the Python-checkins mailing list