You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compat.py 642B

12345678910111213141516171819
  1. __author__ = "Per Fagrell"
  2. __copyright__ = "Copyright 2013 hamcrest.org"
  3. __license__ = "BSD, see License.txt"
  4. __all__ = ['is_callable']
  5. import sys
  6. # callable was not part of py3k until 3.2, so we create this
  7. # generic is_callable to use callable if possible, otherwise
  8. # we use generic homebrew.
  9. if sys.version_info[0] == 3 and sys.version_info[1] < 2:
  10. def is_callable(function):
  11. """Return whether the object is callable (i.e., some kind of function)."""
  12. if function is None:
  13. return False
  14. return any("__call__" in klass.__dict__ for klass in type(function).__mro__)
  15. else:
  16. is_callable = callable