itercompat.py 532 B

123456789101112131415161718192021
  1. # RemovedInDjango60Warning: Remove this entire module.
  2. import warnings
  3. from django.utils.deprecation import RemovedInDjango60Warning
  4. def is_iterable(x):
  5. "An implementation independent way of checking for iterables"
  6. warnings.warn(
  7. "django.utils.itercompat.is_iterable() is deprecated. "
  8. "Use isinstance(..., collections.abc.Iterable) instead.",
  9. RemovedInDjango60Warning,
  10. stacklevel=2,
  11. )
  12. try:
  13. iter(x)
  14. except TypeError:
  15. return False
  16. else:
  17. return True