fix: move _torch_available before usage and use importlib.util.find_spec

Fixes ruff F821 (undefined name) and F401 (unused import) errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Deep Mehta
2026-01-24 15:34:29 +05:30
parent f4623c0e1b
commit 17eed38750

View File

@@ -1,8 +1,15 @@
"""Tests for external cache provider API."""
import importlib.util
import pytest
from typing import Optional
def _torch_available() -> bool:
"""Check if PyTorch is available."""
return importlib.util.find_spec("torch") is not None
from comfy_execution.cache_provider import (
CacheProvider,
CacheContext,
@@ -347,12 +354,3 @@ class MockCacheProvider(CacheProvider):
def on_store(self, context: CacheContext, value: CacheValue) -> None:
self.stores.append((context, value))
def _torch_available() -> bool:
"""Check if PyTorch is available."""
try:
import torch
return True
except ImportError:
return False