Skip to content

fix(parser): stop Python imports at line boundaries - #1006

Open
Jackkp0t wants to merge 1 commit into
modelscope:mainfrom
Jackkp0t:fix/python-import-line-boundaries
Open

Jackkp0t wants to merge 1 commit into
modelscope:mainfrom
Jackkp0t:fix/python-import-line-boundaries

Conversation

@Jackkp0t

Copy link
Copy Markdown

Change Summary

The ordinary Python import regex includes newlines in its whitespace classes. Given two consecutive project imports, parse_imports() can return no dependencies; with aliases on both lines, it raises ValueError: too many values to unpack. This affects the dependency checks used by Code Genesis.

Limit this regex to horizontal whitespace so it stops at each import line. Preserve spaces, tabs and formfeeds, comma-separated imports, and existing alias extraction. Add public-API regression tests with actual project files covering LF/CRLF, consecutive imports, a following from import, and a following statement.

Related issue number

No linked issue. All 27 open PR file lists were checked; neither target file is modified by another PR. The merged import-parser fix #811 addresses relative paths, a separate problem.

Validation

  • New tests before the fix: 8 failed, 3 passed; after the fix: 11 passed (python -m pytest tests/utils/test_python_import_lines.py --disable-socket -q).
  • Complete parser tests: 63 passed, 1 failed on Windows. The same existing test_relative_import_double_dot assertion fails on the unchanged baseline (52 passed, 1 failed): it expects / while the resolved path uses \. This PR leaves path resolution unchanged.
  • All applicable file-level pre-commit hooks and git diff --check passed.
  • A full pre-commit run --all-files was already run against the same upstream baseline during the preceding snapshot contribution; unrelated baseline lint/format failures remain (including file_lock.py E731 and skills_manager.py E305). This independent worktree contains only this parser fix and its new tests.

Checklist

  • The pull request title is a good summary of the changes
  • Unit tests for the changes exist
  • Run pre-commit install and pre-commit run --all-files before git commit, and passed lint check (baseline failures described above)
  • Documentation reflects the changes where applicable (regex comment clarified)

Prepared with Codex, including regression tests and a separate AI code review.

This branch has not been deployed

No deployments
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.

1 participant