python-zk / kazoo

Kazoo is a high-level Python library that makes it easier to use Apache Zookeeper.
https://kazoo.readthedocs.io
Apache License 2.0
1.3k stars 387 forks source link

DataWatch is using TypeError to detect the arity of callback function #475

Open liudangyi opened 7 years ago

liudangyi commented 7 years ago

In kazoo/recipe/watchers.py line 163.

            try:
                result = self._func(data, stat, event)
            except TypeError:
                result = self._func(data, stat)

It's too terrible since a lot of error could raise a TypeError. Two better ways may be

  1. Like ChildrenWatch, add a send_event parameter.
  2. Use len(inspect.getargspec(self._func).args) to decide the arity first.