diff --git a/dask/base.py b/dask/base.py index f2b8014cc71..fb22932383c 100644 --- a/dask/base.py +++ b/dask/base.py @@ -223,7 +223,11 @@ def is_dask_collection(x) -> bool: else: raise TypeError("Unfamiliar with xarray type", type(x)) else: - return hasattr(x, "__dask_graph__") + return ( + hasattr(x, "__dask_graph__") + and callable(x.__dask_graph__) + and not isinstance(x, type) + ) except (AttributeError, TypeError): return False diff --git a/dask/tests/test_base.py b/dask/tests/test_base.py index d0fc9489c95..b19d4a7130e 100644 --- a/dask/tests/test_base.py +++ b/dask/tests/test_base.py @@ -677,7 +677,6 @@ def __dask_graph__(self): x = delayed(1) + 2 assert is_dask_collection(x) - assert not is_dask_collection(2) assert is_dask_collection(DummyCollection({})) assert not is_dask_collection(DummyCollection)