Commit eee0ffc
authored
fix(ci): silence ty unresolved-import for optional PIL in image_loader [SDK-307] (#4193)
## What & why
The **Code Quality** CI job (`uv run ty check .`) is currently **red on
every PR**, including already-merged ones — the check is broken
repo-wide, not by any individual PR.
**Root cause:** `cognee/infrastructure/loaders/core/image_loader.py`
imports Pillow (`PIL`) for its optional EXIF-metadata and
perceptual-hash features. The imports are guarded at runtime with
`try/except ImportError` (graceful degradation), so Pillow is genuinely
optional — but it is **not** installed by the Code Quality job (which
runs only `uv sync --extra dev`; Pillow reaches the env only
transitively via the `unstructured` extra). Because
`[tool.ty.src].include` covers `cognee/infrastructure/loaders`, ty
type-checks that file and emits **5 `unresolved-import` diagnostics**
for `PIL` / `PIL.ExifTags`.
**Evidence it's pre-existing and repo-wide:** Code Quality = FAILURE on
#4155, #4156, #4134 and the already-merged #4153; `image_loader.py` and
the ty config are byte-identical across the last ~34 dev commits.
## Change
Add an inline `# ty: ignore[unresolved-import]` at each of the 5
optional `PIL` import sites — matching the existing convention in the
repo (e.g. `litellm_instructor/.../azure_openai/adapter.py`). These
imports are intentionally optional and already runtime-guarded, so
suppressing the *static* unresolved-import there is the correct
semantics. **No dependency or lockfile change**, and the `try/except`
guards are untouched.
Alternative considered: add Pillow to the `dev` extra so ty can actually
resolve it (real type coverage of the PIL path) — heavier (lockfile
change) and inconsistent with how other optional imports are handled;
left as a possible later improvement.
## Verification (local, ty resolving against a full dev env with Pillow
absent)
- `ty check .`: **5 diagnostics → 0** ("All checks passed!").
- `ruff check` and `ruff format --check`: clean.
Linear: **SDK-307**. Unblocks the Code Quality gate for all open PRs.
🤖 Generated with [Claude Code](https://claude.com/claude-code)1 file changed
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
| 174 | + | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
| 237 | + | |
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
| 273 | + | |
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | | - | |
| 296 | + | |
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
| |||
0 commit comments