]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make names in __future__.py bind to class instances instead of 2-tuples.
authorTim Peters <tim.peters@gmail.com>
Fri, 2 Mar 2001 02:53:08 +0000 (02:53 +0000)
committerTim Peters <tim.peters@gmail.com>
Fri, 2 Mar 2001 02:53:08 +0000 (02:53 +0000)
Suggested on c.l.py by William Tanksley, and I like it.

Lib/__future__.py
Lib/test/test___future__.py

index 2c263b7872e204de014ebbee4dda2f845766c794..3008f22e184ff694fefee88be404fe22c52f8e6a 100644 (file)
@@ -2,11 +2,7 @@
 
 Each line is of the form:
 
-    FeatureName = ReleaseInfo
-
-ReleaseInfo is a pair of the form:
-
-    (OptionalRelease, MandatoryRelease)
+    FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease) ")"
 
 where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
 of the same form as sys.version_info:
@@ -38,7 +34,36 @@ to use the feature in question, but may continue to use such imports.
 MandatoryRelease may also be None, meaning that a planned feature got
 dropped.
 
-No line is ever to be deleted from this file.
+Instances of class _Feature have two corresponding methods,
+.getOptionalRelease() and .getMandatoryRelease().
+
+No feature line is ever to be deleted from this file.
 """
 
-nested_scopes = (2, 1, 0, "beta", 1), (2, 2, 0, "final", 0)
+class _Feature:
+    def __init__(self, optionalRelease, mandatoryRelease):
+        self.optional = optionalRelease
+        self.mandatory = mandatoryRelease
+
+    def getOptionalRelease(self):
+        """Return first release in which this feature was recognized.
+
+        This is a 5-tuple, of the same form as sys.version_info.
+        """
+
+        return self.optional
+
+    def getMandatoryRelease(self):
+        """Return release in which this feature will become mandatory.
+
+        This is a 5-tuple, of the same form as sys.version_info, or, if
+        the feature was dropped, is None.
+        """
+
+        return self.mandatory
+
+    def __repr__(self):
+        return "Feature(" + `self.getOptionalRelease()` + ", " + \
+                            `self.getMandatoryRelease()` + ")"
+
+nested_scopes = _Feature((2, 1, 0, "beta", 1), (2, 2, 0, "final", 0))
index 3ae1cf1f21c28f83df5de4cac5703eea2e5364da..b8ef120d04a06c7a62a80451f880cf909fd73db2 100644 (file)
@@ -10,10 +10,9 @@ for feature in features:
     value = getattr(__future__, feature)
     if verbose:
         print "Checking __future__ ", feature, "value", value
-    verify(type(value) is TupleType, "feature value isn't tuple")
-    verify(len(value) == 2, "feature value isn't 2-tuple")
 
-    optional, mandatory = value
+    optional = value.getOptionalRelease()
+    mandatory = value.getMandatoryRelease()
 
     verify(type(optional) is TupleType, "optional isn't tuple")
     verify(len(optional) == 5, "optional isn't 5-tuple")