Skip to content

fix: resolve all Ruff linting errors (F403, F405, F401, E402, E722, F821)#209

Open
ennajari wants to merge 2 commits intoVectifyAI:mainfrom
ennajari:fix/ruff-linting-errors
Open

fix: resolve all Ruff linting errors (F403, F405, F401, E402, E722, F821)#209
ennajari wants to merge 2 commits intoVectifyAI:mainfrom
ennajari:fix/ruff-linting-errors

Conversation

@ennajari
Copy link
Copy Markdown

@ennajari ennajari commented Apr 1, 2026

What this PR does

Fixes 120 → 0 Ruff linting errors across the codebase by addressing every violation category reported by ruff check ..


Changes by rule

F403 / F405 — Wildcard imports replaced with explicit imports

Replaced all from .utils import * and from pageindex import * patterns with explicit named imports in:

  • pageindex/page_index.py
  • pageindex/page_index_md.py
  • pageindex/__init__.py (also adds __all__ for proper re-export)
  • run_pageindex.py

This makes all name dependencies explicit and eliminates undefined-name false positives.

F401 — Unused imports

  • Added __all__ to pageindex/__init__.py so re-exported names (md_to_tree, PageIndexClient, etc.) are recognised as intentional
  • Removed unused ModelSettings import from examples/agentic_vectorless_rag_demo.py (only referenced in a commented-out line)

E402 — Module-level import not at top of file

  • pageindex/utils.py: moved yaml, Path, and config imports before the load_dotenv() call; sorted stdlib imports alphabetically
  • cookbook/agentic_retrieval.ipynb: moved from pprint import pprint before the function definition inside the affected cell

F821 — Undefined name

  • pageindex/utils.py: added missing import re (used by get_first_start_page_from_text and get_last_start_page_from_text)

E722 — Bare except

  • pageindex/utils.py: except:except Exception:
  • pageindex/page_index_md.py: except:except ImportError: (this block handles relative vs absolute import fallback)

Auto-fixed (22 errors)

Applied ruff check --fix for: F541 (f-strings without placeholders), E401 (multiple imports on one line), F811 (redefined-while-unused imports), F401 (simple unused imports).


No breaking changes

  • All public API symbols are preserved; __all__ in __init__.py explicitly re-exports the same names previously available via star import
  • Default behaviour of all CLI flags and library functions is unchanged
  • tqdm optional fallback is preserved in page_index_md.py

Verification

$ ruff check .
All checks passed!

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

…821)

- Replace wildcard imports (`from .utils import *`) with explicit named
  imports in page_index.py, page_index_md.py, __init__.py, and
  run_pageindex.py, eliminating 79 F405 and 5 F403 violations
- Add __all__ to __init__.py to properly declare the public re-exports
- Fix import order in utils.py (E402): move yaml/Path/config imports
  before load_dotenv() call; sort stdlib imports alphabetically
- Add missing `import re` in utils.py (F821) used by regex helpers
- Replace bare `except:` with `except Exception:` in utils.py and
  `except ImportError:` in page_index_md.py (E722)
- Remove unused `ModelSettings` import in examples/agentic_vectorless_rag_demo.py (F401)
- Move `from pprint import pprint` before function definition in
  cookbook/agentic_retrieval.ipynb cell to fix E402 in notebooks
- Auto-fix 22 additional errors: F541 (f-strings), E401 (multiple
  imports per line), F811 (redefined imports), F401 (unused imports)

No breaking changes: all public APIs preserved; __all__ exposes the
same symbols previously accessible via star import.
@ennajari ennajari force-pushed the fix/ruff-linting-errors branch from 77c145f to 9fab668 Compare April 1, 2026 13:52
- Migrate PyPDF2 (CVE-2023-36464) to pypdf>=4.0.0
- Replace generic Exception raises with RuntimeError in page_index.py
- Fix float equality comparison: accuracy == 1.0 -> accuracy >= 1.0
- Rename unused parameters: N->n, doc->_doc, toc_page_list->_toc_page_list
- Remove redundant continue statement in fix_incorrect_toc
- Replace list(data.keys()) with data.keys() to avoid unnecessary copy
- Fix star imports with explicit named imports in page_index_md.py
- Replace bare except with except ImportError
- Use asyncio.to_thread for async file I/O in md_to_tree
- Add ruff.toml to exclude .claude worktree directory from linting
- Fix E402, F401, F811 issues in notebooks and example files
@ennajari
Copy link
Copy Markdown
Author

ennajari commented Apr 1, 2026

Context

This PR is a follow-up to #192 (CLI improvements) and focuses exclusively on static analysis fixes — no logic changes.

Tools used

Tool Issues found Issues fixed
Ruff 120 errors 120
Trivy 1 CVE (PyPDF2) 1
SonarQube 33 issues 33

Key changes

  • requirements.txtPyPDF2==3.0.1pypdf>=4.0.0 (fixes CVE-2023-36464)
  • pageindex/page_index.pyraise Exceptionraise RuntimeError, float equality fix, unused param renames
  • pageindex/page_index_md.py — explicit imports, asyncio.to_thread for async file I/O, except ImportError
  • pageindex/utils.py — PyPDF2 migration, reduced cognitive complexity, mutable default fix
  • Notebooks + examples — E402 / F401 / F811 auto-fixes

No public API changes. ruff check . passes with 0 errors.
@ennajari

@Abdelilah04116
Copy link
Copy Markdown

That's interesting for the project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants