Rev 4100: Review feedback. in http://people.ubuntu.com/~robertc/baz2.0/pending/Hooks.docs

Robert Collins robertc at robertcollins.net
Tue Mar 10 03:05:24 GMT 2009


At http://people.ubuntu.com/~robertc/baz2.0/pending/Hooks.docs

------------------------------------------------------------
revno: 4100
revision-id: robertc at robertcollins.net-20090310030521-1ew21nsm0ktgcv26
parent: robertc at robertcollins.net-20090310011651-73eyp8l970t21ah8
committer: Robert Collins <robertc at robertcollins.net>
branch nick: Hooks.docs
timestamp: Tue 2009-03-10 14:05:21 +1100
message:
  Review feedback.
=== modified file 'bzrlib/hooks.py'
--- a/bzrlib/hooks.py	2009-03-10 01:16:51 +0000
+++ b/bzrlib/hooks.py	2009-03-10 03:05:21 +0000
@@ -43,7 +43,7 @@
         """Create a hook which can have callbacks registered for it.
 
         :param hook: The hook to create. An object meeting the protocol of
-            bzrlib.hooks.Hook. It's name is used as the key for future
+            bzrlib.hooks.HookPoint. It's name is used as the key for future
             lookups.
         """
         if hook.name in self:
@@ -122,7 +122,7 @@
         self._callable_names[a_callable] = name
 
 
-class Hook(object):
+class HookPoint(object):
     """A single hook that clients can register to be called back when it fires.
 
     :ivar name: The name of the hook.
@@ -136,7 +136,7 @@
     """
 
     def __init__(self, name, doc, introduced, deprecated):
-        """Create a Hook.
+        """Create a HookPoint.
         
         :param name: The name of the hook, for clients to use when registering.
         :param doc: The docs for the hook.
@@ -152,7 +152,7 @@
         self._callback_names = {}
 
     def docs(self):
-        """Generate the documentation for this Hook.
+        """Generate the documentation for this HookPoint.
         
         :return: A string terminated in \n.
         """
@@ -176,9 +176,9 @@
         return '\n'.join(strings)
 
     def hook(self, callback, callback_label):
-        """Call this hook with callback, using callback_label to describe it.
+        """Register a callback to be called when this HookPoint fires.
 
-        :param callback: The callable to use when this Hook fires.
+        :param callback: The callable to use when this HookPoint fires.
         :param callback_label: A label to show in the UI while this callback is
             processing.
         """
@@ -190,7 +190,7 @@
 
     def __repr__(self):
         strings = []
-        strings.append("<bzrlib.hooks.Hook(")
+        strings.append("<%s(" % type(self).__name__)
         strings.append(self.name)
         strings.append("), callbacks=[")
         for callback in self._callbacks:

=== modified file 'bzrlib/tests/test_hooks.py'
--- a/bzrlib/tests/test_hooks.py	2009-03-10 01:16:51 +0000
+++ b/bzrlib/tests/test_hooks.py	2009-03-10 03:05:21 +0000
@@ -18,7 +18,7 @@
 
 from bzrlib import errors
 from bzrlib.hooks import (
-    Hook,
+    HookPoint,
     Hooks,
     )
 from bzrlib.errors import (
@@ -35,7 +35,7 @@
         hooks = Hooks()
         doc = ("Invoked after changing the tip of a branch object. Called with"
             "a bzrlib.branch.PostChangeBranchTipParams object")
-        hook = Hook("post_tip_change", doc, (0, 15), None)
+        hook = HookPoint("post_tip_change", doc, (0, 15), None)
         hooks.create_hook(hook)
         self.assertEqual(hook, hooks['post_tip_change'])
 
@@ -43,8 +43,8 @@
         hooks = Hooks()
         doc = ("Invoked after changing the tip of a branch object. Called with"
             "a bzrlib.branch.PostChangeBranchTipParams object")
-        hook = Hook("post_tip_change", doc, (0, 15), None)
-        hook2 = Hook("post_tip_change", None, None, None)
+        hook = HookPoint("post_tip_change", doc, (0, 15), None)
+        hook2 = HookPoint("post_tip_change", None, None, None)
         hooks.create_hook(hook)
         self.assertRaises(errors.DuplicateKey, hooks.create_hook, hook2)
         self.assertEqual(hook, hooks['post_tip_change'])
@@ -53,10 +53,10 @@
         """docs() should return something reasonable about the Hooks."""
         hooks = Hooks()
         hooks['legacy'] = []
-        hook1 = Hook('post_tip_change',
+        hook1 = HookPoint('post_tip_change',
             "Invoked after the tip of a branch changes. Called with "
             "a ChangeBranchTipParams object.", (1, 4), None)
-        hook2 = Hook('pre_tip_change',
+        hook2 = HookPoint('pre_tip_change',
             "Invoked before the tip of a branch changes. Called with "
             "a ChangeBranchTipParams object. Hooks should raise "
             "TipChangeRejected to signal that a tip change is not permitted.",
@@ -138,7 +138,7 @@
     def test___init__(self):
         doc = ("Invoked after changing the tip of a branch object. Called with"
             "a bzrlib.branch.PostChangeBranchTipParams object")
-        hook = Hook("post_tip_change", doc, (0, 15), None)
+        hook = HookPoint("post_tip_change", doc, (0, 15), None)
         self.assertEqual(doc, hook.__doc__)
         self.assertEqual("post_tip_change", hook.name)
         self.assertEqual((0, 15), hook.introduced)
@@ -148,7 +148,7 @@
     def test_docs(self):
         doc = ("Invoked after changing the tip of a branch object. Called with"
             " a bzrlib.branch.PostChangeBranchTipParams object")
-        hook = Hook("post_tip_change", doc, (0, 15), None)
+        hook = HookPoint("post_tip_change", doc, (0, 15), None)
         self.assertEqual("post_tip_change\n"
             "---------------\n"
             "\n"
@@ -159,7 +159,7 @@
             "bzrlib.branch.PostChangeBranchTipParams object\n", hook.docs())
 
     def test_hook(self):
-        hook = Hook("foo", "no docs", None, None)
+        hook = HookPoint("foo", "no docs", None, None)
         def callback():
             pass
         hook.hook(callback, "my callback")
@@ -167,11 +167,11 @@
 
     def test___repr(self):
         # The repr should list all the callbacks, with names.
-        hook = Hook("foo", "no docs", None, None)
+        hook = HookPoint("foo", "no docs", None, None)
         def callback():
             pass
         hook.hook(callback, "my callback")
         callback_repr = repr(callback)
         self.assertEqual(
-            '<bzrlib.hooks.Hook(foo), callbacks=[%s(my callback)]>' %
+            '<HookPoint(foo), callbacks=[%s(my callback)]>' %
             callback_repr, repr(hook))




More information about the bazaar-commits mailing list