Repository: dask/dask

Issue:
Callback __init__() overrides subclass callback definitions 
The `__init__` method in `Callback` is:
```
    def __init__(self, start=None, pretask=None, posttask=None, finish=None):
        self._start = start
        self._pretask = pretask
        self._posttask = posttask
        self._finish = finish
```
which overrides callbacks defined in subclasses, e.g.:
```
class TaskCounter(Callback):
    def _pretask(self, key, dask, state):
        count(key, dask, state)
```
which doesn't work, while:
```
class TaskCounter(Callback):
    def __init__(self):
        pass

    def _pretask(self, key, dask, state):
        count(key, dask, state)
```
does.  Not sure quite what desired behavior here is, but the example in the docs:
```
class PrintKeys(Callback):
    def _pretask(self, key, dask, state):
        """Print the key of every task as it's started"""
        print("Computing: {0}!".format(repr(key)))
```
doesn't work.

Discussion:

Patch:
diff --git a/dask/callbacks.py b/dask/callbacks.py
index 55e7a5a1b..61aba8676 100644
--- a/dask/callbacks.py
+++ b/dask/callbacks.py
@@ -44,10 +44,14 @@ class Callback(object):
     """
 
     def __init__(self, start=None, pretask=None, posttask=None, finish=None):
-        self._start = start
-        self._pretask = pretask
-        self._posttask = posttask
-        self._finish = finish
+        if start:
+            self._start = start
+        if pretask:
+            self._pretask = pretask
+        if posttask:
+            self._posttask = posttask
+        if finish:
+            self._finish = finish
 
     @property
     def _callback(self):


Test patch:
diff --git a/dask/tests/test_callbacks.py b/dask/tests/test_callbacks.py
new file mode 100644
index 000000000..b4f4b8396
--- /dev/null
+++ b/dask/tests/test_callbacks.py
@@ -0,0 +1,14 @@
+from dask.async import get_sync
+from dask.callbacks import Callback
+
+def test_callback():
+    flag = [False]
+
+    class MyCallback(Callback):
+        def _start(self, dsk):
+            flag[0] = True
+
+    with MyCallback():
+        get_sync({'x': 1}, 'x')
+
+    assert flag[0] is True