]> granicus.if.org Git - python/commitdiff
SF bug #663701: sets module review
authorRaymond Hettinger <python@rcn.com>
Fri, 14 Feb 2003 03:42:11 +0000 (03:42 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 14 Feb 2003 03:42:11 +0000 (03:42 +0000)
Renamed hook methods to use the double underscore convention.

Doc/lib/libsets.tex
Lib/sets.py

index 9c5998a565931a1843f13ec085f643923cfe361c..4d87a4fb2d61e2b2008134720cf6d296d82a270e 100644 (file)
@@ -203,23 +203,23 @@ before being added as a set element.
 
 The mechanism is to always add a hashable element, or if it is not
 hashable, the element is checked to see if it has an
-\method{_as_immutable()} method which returns an immutable equivalent.
+\method{__as_immutable__()} method which returns an immutable equivalent.
 
-Since \class{Set} objects have a \method{_as_immutable()} method
+Since \class{Set} objects have a \method{__as_immutable__()} method
 returning an instance of \class{ImmutableSet}, it is possible to
 construct sets of sets.
 
 A similar mechanism is needed by the \method{__contains__()} and
 \method{remove()} methods which need to hash an element to check
 for membership in a set.  Those methods check an element for hashability
-and, if not, check for a \method{_as_temporarily_immutable()} method
+and, if not, check for a \method{__as_temporarily_immutable__()} method
 which returns the element wrapped by a class that provides temporary
 methods for \method{__hash__()}, \method{__eq__()}, and \method{__ne__()}.
 
 The alternate mechanism spares the need to build a separate copy of
 the original mutable object.
 
-\class{Set} objects implement the \method{_as_temporarily_immutable()}
+\class{Set} objects implement the \method{__as_temporarily_immutable__()}
 method which returns the \class{Set} object wrapped by a new class
 \class{_TemporarilyImmutableSet}.
 
index 9604249c6ff36d66b36bad4fc15d1a627367bac0..0824fb1859bf8012e5b2f6f0e864e1d3d2e03d94 100644 (file)
@@ -248,7 +248,7 @@ class BaseSet(object):
         try:
             return element in self._data
         except TypeError:
-            transform = getattr(element, "_as_temporarily_immutable", None)
+            transform = getattr(element, "__as_temporarily_immutable__", None)
             if transform is None:
                 raise # re-raise the TypeError exception we caught
             return transform() in self._data
@@ -325,7 +325,7 @@ class BaseSet(object):
                         data[element] = value
                     return
                 except TypeError:
-                    transform = getattr(element, "_as_immutable", None)
+                    transform = getattr(element, "__as_immutable__", None)
                     if transform is None:
                         raise # re-raise the TypeError exception we caught
                     data[transform()] = value
@@ -335,7 +335,7 @@ class BaseSet(object):
                 try:
                     data[element] = value
                 except TypeError:
-                    transform = getattr(element, "_as_immutable", None)
+                    transform = getattr(element, "__as_immutable__", None)
                     if transform is None:
                         raise # re-raise the TypeError exception we caught
                     data[transform()] = value
@@ -464,7 +464,7 @@ class Set(BaseSet):
         try:
             self._data[element] = True
         except TypeError:
-            transform = getattr(element, "_as_immutable", None)
+            transform = getattr(element, "__as_immutable__", None)
             if transform is None:
                 raise # re-raise the TypeError exception we caught
             self._data[transform()] = True
@@ -477,7 +477,7 @@ class Set(BaseSet):
         try:
             del self._data[element]
         except TypeError:
-            transform = getattr(element, "_as_temporarily_immutable", None)
+            transform = getattr(element, "__as_temporarily_immutable__", None)
             if transform is None:
                 raise # re-raise the TypeError exception we caught
             del self._data[transform()]
@@ -496,11 +496,11 @@ class Set(BaseSet):
         """Remove and return an arbitrary set element."""
         return self._data.popitem()[0]
 
-    def _as_immutable(self):
+    def __as_immutable__(self):
         # Return a copy of self as an immutable set
         return ImmutableSet(self)
 
-    def _as_temporarily_immutable(self):
+    def __as_temporarily_immutable__(self):
         # Return self wrapped in a temporarily immutable set
         return _TemporarilyImmutableSet(self)