Skip to content

[FIX] detect nested and indented Python imports - #2955

Merged
Roman Lutz (romanlutz) merged 5 commits into
microsoft:mainfrom
barry166:fix/2948-package-imports
Oct 10, 2026
Merged

Roman Lutz (romanlutz) merged 5 commits into
microsoft:mainfrom
barry166:fix/2948-package-imports

Conversation

@barry166

Copy link
Copy Markdown
Contributor

Description

Fixes #2948 by allowing the Python package hallucination scorer to detect imports inside indented blocks and from package.submodule import ... statements. Dotted module paths are reduced to their top-level package name before comparison with the known-package set.

Tests and Documentation

  • Added regression coverage for indented imports and dotted from imports.
  • uv run pytest tests/unit/score/test_package_hallucination_scorer.py (33 passed)
  • uv run ruff check pyrit/score/true_false/regex/package_hallucination_scorer.py tests/unit/score/test_package_hallucination_scorer.py

@romanlutz Roman Lutz (romanlutz) self-assigned this Oct 9, 2026
Roman Lutz (romanlutz) and others added 4 commits October 9, 2026 09:09
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Ignore string literals and comments before extracting Python imports, and join explicit continuations so imported symbols are not treated as packages. Add independent extraction and score-level regressions while preserving Markdown and incomplete-response support.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 10, 2026
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 10, 2026
Merged via the queue into microsoft:main with commit ac93b79 Oct 10, 2026
55 checks passed
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.

PackageHallucinationScorer (Python) misses from pkg.sub import x and indented imports

2 participants