Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappings

未关闭 适合新手
#5,405 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@omisha123 已经在做这个了。

开始于 2026年11月1日。

  • #5406 来自 @omisha123 —— 未关闭

评估

难度
2/5
预计耗时
半天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
tooling

调研方向

从 src/licensedcode/required_phrases.py 第 205 行附近的第 1 项开始,其中 license_expression 属性计算了 self.rule.license_expression 却没有返回它,然后检查该类中其他属性如何读取它们的值。第 2 项位于 src/commoncode/command.py 第 319 行附近,其中 find_in_path 在导入时计算 searchable_paths()。运行一个小脚本,在导入后修改 PATH 来复现问题。第 3 项需要维护者就 src/packagedcode/rubygems.py 和 src/packagedcode/alpine.py 中的预期值作出决定,因此除非讨论线程已经确定,否则不要改动。完成的标准是修复后的属性返回预期值,并且相关测试通过。

由索引模型根据 Issue 内容生成。

描述

bug

Summary

A static scan of src/ found four bugs that fail silently (no exception).
Each was reproduced with a small standalone script.

1. IsRequiredPhrase.license_expression always returns None

src/licensedcode/required_phrases.py (~line 205):

@property
def license_expression(self):
    self.rule.license_expression      # missing `return`

Repro: IsRequiredPhrase(rule=<rule with license_expression="mit">, ...) .license_expression returns None.
Fix: return self.rule.license_expression.

2. find_in_path ignores PATH changes made after import

src/commoncode/command.py (~line 319):

def find_in_path(filename, searchable_paths=searchable_paths()):

The default is evaluated once at import time, so PATH changes made afterwards
are ignored. The parameter also shadows the searchable_paths() function.
Repro: import the module, then prepend a directory containing mytool to
os.environ["PATH"]. find_in_path("mytool") returns None, but
find_in_path("mytool", searchable_paths()) returns the path.
Fix: default to None and call searchable_paths() inside the function.

3. Duplicate dict keys with conflicting values silently override mappings

Python keeps only the last value, so the earlier entries are dead.

  • src/packagedcode/rubygems.py (LICENSES_MAPPING, lines 679-680):
    'LGPL' maps to 'lgpl' and then to 'lgpl-2.0-plus'.
  • src/packagedcode/alpine.py (DECLARED_TO_SPDX):
    • 'as-is' (lines 1619, 1701): licenseref-scancode-free-unknown vs
      licenseref-scancode-unknown-license-reference
    • 'custom:tu-berlin-2.0' (lines 1690, 1715):
      licenseref-scancode-unknown-license-reference vs tu-berlin-2.0

The maintainers should decide which value is intended and remove the other.

4. Duplicate key in default ignores (harmless, cleanup)

src/commoncode/ignore.py lines 204-205 repeat "autogen.sh".

Environment

Found by static analysis (ruff F601, B008, B018) at commit 05a98f66.
Please verify the intended values for item 3 before changing them.

主要语言
Python
星标
2.7k
派生
848
平均合并
2 天 19 小时
30 天内合并 PR
8

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aboutcode-org/scancode-toolkit 的其他 Issue

查看 aboutcode-org/scancode-toolkit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。