An empirical study of 198 Python repository histories and 95 merged pull requests has found that maintainers frequently revise where third-party packages are declared, with 43.1 percent of 1,115 historical role-reconfiguration events crossing major installation boundaries. Reported by Yulu Cao, Chenghao Su, Yimeng Guo, Qiao Yu, and colleagues in the Journal of King Saud University Computer and Information Sciences, the study also introduces PyRC, a two-stage detector combining conservative static analysis with large language model reasoning to identify dependency role mismatches. On a benchmark of 257 manually confirmed historical mismatches, PyRC detected 59.9 percent of cases with GPT-5.6 Sol, 45.9 percent with DeepSeek-v4-flash, and 37.0 percent with Llama 3.1 8B, compared with 28.0 percent for static analysis alone. Across 192 previously unseen Python projects, PyRC using DeepSeek-v4-flash flagged 200 candidates in 81 repositories, and manual review confirmed 159 of 195 decidable reports, yielding 81.5 percent precision.
Python projects declare third-party libraries across heterogeneous files—including standardized pyproject.toml metadata under PEP 508, setup.py, setup.cfg, requirements text files, and tool-specific configurations for Poetry, PDM, uv, tox, and nox—without a single explicit role field. The authors normalized these declarations into four role families: runtime for default installations, optional for separately selected features, development for contributor tasks such as testing and documentation, and build for isolated distribution building. Because one package can legitimately serve multiple installation scenarios, role membership is set-valued rather than a single label. The study distinguishes dependency role reconfiguration across revisions from dependency role mismatch, a single-revision inconsistency that either leaves a required package unavailable or imposes unnecessary installations on ordinary users. In augint-tools pull request 53, textual was listed only in optional groups despite unconditional dashboard imports, breaking ordinary installations until maintainers moved it into runtime dependencies.
To examine how and why developers revise dependency roles, the researchers constructed two datasets. For the repository-history corpus, they ranked PyPI packages by 30-day downloads, mapped them to canonical public GitHub repositories, and excluded duplicates plus scientific, multi-package, and multi-language repositories. Two of the first 200 eligible repositories lacked retrievable histories, leaving 198 projects. Comparing supported declarations at each non-merge commit against its parent identified 1,115 dependency events across 362 commits in 95 projects, while 103 projects showed no events. For developer motivations, the authors searched GitHub pull request titles for role-conflict keywords, retrieving 120 merged pull requests from 119 repositories. Requiring developer-authored explanations narrowed the corpus to 109 pull requests, and excluding syntax-only moves, non-family edits, and parsing errors left 95 pull requests containing 313 effective role reconfigurations. Two authors independently coded the 109 eligible pull requests, achieving initial agreement of Cohen’s kappa 0.74 before resolving disagreements through discussion.
In the 198 project histories, within-family edits accounted for 634 of 1,115 events, or 56.9 percent, while 481 events, or 43.1 percent, changed role-family membership across 70 projects. Among family-changing events, replacement led at 356 cases, followed by contraction at 86, expansion at 22, and mixed reconfiguration at 17. Multi-role declarations occurred in 24.1 percent of events beforehand and 30.1 percent afterward. In the 95 pull requests, 304 of 313 events were direct transitions, led by runtime to optional at 130 and runtime to development at 116, versus 43 optional-to-runtime and 11 development-to-runtime shifts; 56.5 percent crossed the optional boundary directly. Developer text stated a problem or benefit in 72 of 95 pull requests, or 75.8 percent. All nine pull requests reporting runtime failures moved dependencies toward runtime, while among 67 moving packages out of runtime, 15 cited unnecessary default installations and 12 targeted smaller footprints, exemplified by googlecolab/google-colab-cli pull request 29 trimming installations from 57 to 51 packages.
Drawing on these findings, the researchers designed PyRC to evaluate every directly declared dependency in a project snapshot, returning a declaration assessment, a ranked set of suitable roles, supporting evidence, and provenance. Stage 1 applies conservative static analysis. It normalizes supported manifests and parses Python and Notebook files into abstract syntax trees, recording import paths, file locations, reachability from package initializers, main modules, and entry points, and guarded contexts including TYPE_CHECKING blocks, conditionals, try-except ImportError handlers, and constant dynamic imports. Structured parsers also inspect TOML, INI, JSON, and YAML configurations for tools such as pytest, tox, Ruff, mypy, Flake8, coverage, Pyright, pre-commit, and MkDocs. Stage 1 emits a terminal mismatch only when a direct declaration exists, distribution-to-import mapping is resolved, and repository evidence satisfies strict incompatibility conditions. Cases with ambiguous feature boundaries or guarded imports are routed as unresolved or not-reported to Stage 2 rather than treated as correct.
Stage 2 applies large language model reasoning to dependencies not reported as terminal mismatches by Stage 1. A separate lexical retriever scans repository text files—including source code, configuration files, documentation, and workflows—for the canonical package name and hyphenated, underscored, dotted, or separator-free variants. Matching lines are merged with five surrounding lines on each side, capped at four windows per file and 120,000 characters total alongside up to two README or CONTRIBUTING prefixes. Crucially, this context omits Stage 1 statuses and conclusions so the model evaluates each case independently. A fixed zero-shot prompt defines roles by installation scenario, requests set-valued ranked roles first, and separately judges whether the complete current declaration is compatible with supported usage, allowing tests to reuse justified runtime dependencies. Every judgment must cite excerpt identifiers in validated JSON. In scverse/cellrank, Stage 2 interpreted a custom helper naming a scvelo extra, ranking optional above development and rejecting runtime placement.
To measure effectiveness, two reviewers independently assessed pre-change snapshots for the 313 pull-request reconfigurations, initially agreeing on 93.6 percent of cases with Cohen’s kappa 0.77. Excluding 40 changes dependent on concurrent code or policy edits, such as molecule pull request 2921, and 16 unresolved cases left a positive-only benchmark of 257 confirmed mismatches, 200 moving from runtime to development or optional roles. Under a paired, zero-temperature setup without retries, complete PyRC configurations beat prompting-only baselines. PyRC with GPT-5.6 Sol detected 154 mismatches, or 59.9 percent, achieving 52.9 percent Hit@1, 54.9 percent Hit@2, and 88.3 percent Top-1 agreement among detections. PyRC with DeepSeek-v4-flash detected 118 cases, or 45.9 percent, with 42.0 percent Hit@1 and 91.5 percent Top-1 agreement, while PyRC with Llama 3.1 8B detected 95 cases, or 37.0 percent, lifting Llama’s Hit@1 from 8.2 percent in prompting alone to 30.0 percent. Resolving 72 cases statically also cut DeepSeek-v4-flash consumption from 1,645,911 to 1,133,567 tokens.
Recall varied sharply by migration direction. Across 114 runtime-to-development cases, PyRC with GPT-5.6 Sol detected 82, or 71.9 percent, ahead of DeepSeek-v4-flash at 62.3 percent, Llama 3.1 8B at 40.4 percent, and static analysis at 33.3 percent. Runtime-to-optional transitions were hardest across 86 cases, with GPT-5.6 Sol detecting 37, or 43.0 percent, DeepSeek-v4-flash 13, Llama 3.1 8B nine, and static analysis six. Conversely, Llama 3.1 8B led optional-to-runtime detection at 27 of 38 cases, or 71.1 percent, while DeepSeek-v4-flash caught all 11 development-to-runtime cases. On the 183 benchmark cases completed by both deptry 0.25.1 and PyConf, deptry reported two DEP004 role mismatches—its 108 DEP002 unused-dependency alerts did not express role changes—and PyConf flagged 20 import failures, or 11.0 percent, largely in optional-to-runtime cases. Neither existing tool reported counted findings for the 82 runtime-to-development or 60 runtime-to-optional cases, whereas PyRC configurations achieved 33.3 to 56.3 percent recall on the shared subset.
To test real-world usefulness at lower API cost, the team ran PyRC with DeepSeek-v4-flash on 192 previously unseen, actively maintained GitHub repositories linked to PyPI, covering 4,692 dependency targets. PyRC flagged 200 candidates across 81 projects—113 statically and 87 via Stage 2—at a median latency of 2.52 seconds and an estimated API cost of 9.07 US dollars. Two reviewers independently checked all 200 reports, agreeing on 89.9 percent of determinate pairs with Cohen’s kappa 0.69. Adjudication yielded 159 true positives, 36 false positives, and five indeterminate cases, corresponding to 81.5 percent precision overall, 75.9 percent statically, and 89.2 percent for LLM-assisted reports. All 37 optional-to-runtime reports were confirmed, versus 64.7 percent of decidable runtime-to-development reports, and rank-one recommendations matched an accepted role in 95.0 percent of confirmed findings. False positives arose from multi-role packages, example files, and generic requirement lists. Six GitHub issues covering 10 confirmed mismatches drew three positive replies and fixes in joke2k/faker, openai/evals, and siemens/standard-bom-python.
The authors note several limitations. Normalizing heterogeneous manifests into four role families can obscure project-specific semantics, and neither evaluation measures ecosystem-wide prevalence: the positive-only benchmark estimates recall without precision, while the field study measures precision on reported decidable cases without labeling unreported dependencies. Tied first ranks occurred in 4.7 to 5.4 percent of benchmark cases, lowering Hit@1 by 4.7 percentage points if counted as misses. Manual coding involves subjectivity, static parsing can miss unsupported conventions or dynamic behavior, and treating Stage 1 findings as terminal was not proven optimal. Using public repositories also leaves language-model training-data contamination possible; although 218 of 257 cases for Llama 3.1 8B followed its December 2023 cutoff, cutoffs for DeepSeek-v4-flash and GPT-5.6 Sol are undisclosed. Finally, sampling favored popular public PyPI-linked repositories, excluding scientific, proprietary, multi-package, and multi-language projects, and build-role evidence remained sparse, with zero benchmark cases and 23 determinate field reports at 73.9 percent precision.
Subject of Research: Empirical analysis and hybrid static-LLM detection of dependency role mismatches in Python software projects
Article Title: Understanding and detecting dependency role mismatch in Python projects
Article References: Cao, Y., Su, C., Guo, Y., & Yu, Q. (2026). Understanding and detecting dependency role mismatch in Python projects. Journal of King Saud University Computer and Information Sciences, 38(10), Article 1105. https://doi.org/10.1007/s44443-026-01527-3
Image Credits: AI Generated
DOI: 10.1007/s44443-026-01527-3
Keywords: Python packaging, dependency role mismatch, software dependency management, PyRC, static program analysis, large language models, PyPI ecosystem, pyproject.toml, PEP 508, runtime dependencies, optional dependencies, development dependencies, build dependencies, dependency smells, abstract syntax trees, DeepSeek-v4-flash, GPT-5.6 Sol, Llama 3.1 8B

