detectors: packagehallucination misses packages after the first in import a, b - #1991
Open
WatchTree-19 wants to merge 1 commit into
Open
detectors: packagehallucination misses packages after the first in import a, b#1991WatchTree-19 wants to merge 1 commit into
import a, b#1991WatchTree-19 wants to merge 1 commit into
Conversation
jmartin-tech
previously requested changes
Jul 27, 2026
jmartin-tech
left a comment
Collaborator
There was a problem hiding this comment.
This PR includes commits not part of the scope it is meant to address. Please rebase to the described scope only.
…rt a, b` The Python `_extract_package_references` matched `^import\s+(<name>)`, which captures only the first module on the line. `import a, b` is valid Python, so for output like `import os, hallucinated_pkg` the detector extracted only `os` and silently ignored `hallucinated_pkg` -- a false negative: a hallucinated dependency hidden as the second-or-later import on a comma list evades the detector entirely. Split the import clause on commas and take the top-level module of each. Dotted imports (`import a.b`) still reduce to the top-level package, aliases (`import numpy as np`) are handled, and all-real comma imports do not false-positive. The `from ... import` path is unchanged. Added test_pythonpypi_multiple_imports_one_line; it fails on the old regex (the hidden package scores 0.0) and passes with the fix. Signed-off-by: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com>
WatchTree-19
force-pushed
the
fix-pkghalluc-multi-import
branch
from
July 29, 2026 18:49
18222be to
47d3a32
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PythonPypi._extract_package_referencesonly captures the first package on animportline:import a, bis valid Python, so for output likeimport os, hallucinated_pkgthe detector extracts onlyosand silently ignores everything after the comma. That's a false negative in a hallucination detector: a hallucinated dependency hidden as the second-or-later import on a comma-separated line evades detection entirely.Deterministic:
Fix
Split the import clause on commas and take the top-level module of each. Dotted imports (
import a.b→a), aliases (import numpy as np→numpy), and trailing comments are handled; all-real comma imports do not false-positive. Thefrom ... importpath is unchanged.Test
No existing test covered comma-separated imports (the current Python tests are all single-import-per-line). Added
test_pythonpypi_multiple_imports_one_line, which flags a hallucinated package hidden after a real one, handles aliases, and checks an all-real comma line doesn't false-positive. It fails on the old regex (the hidden package scores0.0) and passes with the fix. Full Python suite: 6 passed.Scope note: I kept this to the Python extractor, which is the clear case. The other language extractors use different grammars (Ruby
require, JSimport/require, Rustuse) that don't share the comma-list shape, so they're out of scope here.