[ckan-changes] [okfn/ckan] 4824bb: Use LBYL not EAFP to test for activity methods

noreply at github.com noreply at github.com
Mon Dec 19 16:07:51 UTC 2011


  Branch: refs/heads/feature-1515-activity-streams
  Home:   https://github.com/okfn/ckan

  Commit: 4824bb1693959335b51bb7794c8feeae0a1e1e0b
      https://github.com/okfn/ckan/commit/4824bb1693959335b51bb7794c8feeae0a1e1e0b
  Author: Sean Hammond <seanhammond at lavabit.com>
  Date:   2011-12-19 (Mon, 19 Dec 2011)

  Changed paths:
    M ckan/lib/activity.py

  Log Message:
  -----------
  Use LBYL not EAFP to test for activity methods

To test whether an object supports the activity_stream_item() and
activity_stream_detail() methods use Look Before You Leap (getattr() and
callable()) instead of Easier to Ask Permission than Forgiveness
(AttributeError and TypeError).

Catching an exception and assuming this means that the method you tried
to call doesn't exist is error prone, the method may exist but some line
of the method throws AttributeError or TypeError and fools your calling
code into thinking the method doesn't exist and silencing the error,
when in fact you have a different problem.






More information about the ckan-changes mailing list