[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Using enum.__iter__ for values rather than keys



commit da937730bb3aaa303e584eb3e23494703923c46b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Nov 20 14:20:13 2011 -0800

    Using enum.__iter__ for values rather than keys
    
    Enumeration keys are of very limited use. Iteration over an enumeration should
    give the values instead so swapping values() and __iter__() to be keys() and
    __iter__().
---
 stem/util/enum.py      |   14 +++++++-------
 test/unit/util/enum.py |    6 +++---
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/stem/util/enum.py b/stem/util/enum.py
index 6ce54d0..6891663 100644
--- a/stem/util/enum.py
+++ b/stem/util/enum.py
@@ -4,7 +4,7 @@ constructed as simple type listings, ie:
 >>> insects = Enum("ANT", "WASP", "LADYBUG", "FIREFLY")
 >>> insects.ANT
 'Ant'
->>> insects.values()
+>>> tuple(insects)
 ('Ant', 'Wasp', 'Ladybug', 'Firefly')
 
 with overwritten string counterparts:
@@ -65,15 +65,15 @@ class Enum:
     self._keys = tuple(keys)
     self._values = tuple(values)
   
-  def values(self):
+  def keys(self):
     """
-    Provides an ordered listing of the enumerations in this set.
+    Provides an ordered listing of the enumeration keys in this set.
     
     Returns:
-      tuple with our enum values
+      tuple with our enum keys
     """
     
-    return self._values
+    return self._keys
   
   def index_of(self, value):
     """
@@ -133,9 +133,9 @@ class Enum:
   
   def __iter__(self):
     """
-    Provides an ordered listing of the enumeration keys in this set.
+    Provides an ordered listing of the enums in this set.
     """
     
-    for entry in self._keys:
+    for entry in self._values:
       yield entry
 
diff --git a/test/unit/util/enum.py b/test/unit/util/enum.py
index abdff06..912b64f 100644
--- a/test/unit/util/enum.py
+++ b/test/unit/util/enum.py
@@ -33,7 +33,7 @@ class TestEnum(unittest.TestCase):
     
     insects = stem.util.enum.Enum("ANT", "WASP", "LADYBUG", "FIREFLY")
     self.assertEquals("Ant", insects.ANT)
-    self.assertEquals(("Ant", "Wasp", "Ladybug", "Firefly"), insects.values())
+    self.assertEquals(("Ant", "Wasp", "Ladybug", "Firefly"), tuple(insects))
     
     pets = stem.util.enum.Enum(("DOG", "Skippy"), "CAT", ("FISH", "Nemo"))
     self.assertEquals("Skippy", pets.DOG)
@@ -54,6 +54,6 @@ class TestEnum(unittest.TestCase):
     self.assertEquals(insects.FIREFLY, insects.previous(insects.ANT))
     self.assertEquals(insects.LADYBUG, insects.previous(insects.FIREFLY))
     
-    # __iter__ method
-    self.assertEquals(("ANT", "WASP", "LADYBUG", "FIREFLY"), tuple(insects))
+    # keys method
+    self.assertEquals(("ANT", "WASP", "LADYBUG", "FIREFLY"), insects.keys())
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits