Problem
Multiple files have import statements inside functions and exception handlers instead of at the top of the file.
Worst offenders:
cli.py — 32 inline imports
pipeline/extract.py — 17 inline imports
browser.py — 8 inline imports
security.py — 5 inline imports
pipeline/ocr.py — 4 inline imports
gateways/fax.py — 4 inline imports
crossref.py — 4 inline imports
22 files total with inline imports.
Why it matters
- Makes dependencies hard to see at a glance
- Many are redundant (module already imported at the top)
- Not standard Python style (PEP 8: imports at top)
- Makes it harder for new contributors to understand the codebase
Exception
Lazy imports for heavy optional dependencies (torch, spaCy, GLiNER) inside functions are fine — those are intentional to avoid import-time crashes when the dep isn't installed. Only move imports that are for stdlib or always-available packages.
Fix
Move stdlib inline imports (sys, json, re, os, asyncio, etc.) to the top of each file. Leave optional heavy deps as lazy imports with a comment explaining why.
Problem
Multiple files have
importstatements inside functions and exception handlers instead of at the top of the file.Worst offenders:
cli.py— 32 inline importspipeline/extract.py— 17 inline importsbrowser.py— 8 inline importssecurity.py— 5 inline importspipeline/ocr.py— 4 inline importsgateways/fax.py— 4 inline importscrossref.py— 4 inline imports22 files total with inline imports.
Why it matters
Exception
Lazy imports for heavy optional dependencies (torch, spaCy, GLiNER) inside functions are fine — those are intentional to avoid import-time crashes when the dep isn't installed. Only move imports that are for stdlib or always-available packages.
Fix
Move stdlib inline imports (sys, json, re, os, asyncio, etc.) to the top of each file. Leave optional heavy deps as lazy imports with a comment explaining why.