Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Duplicate keys in alpine DECLARED_TO_SPDX silently discard two license mappings

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

维护者通常 3 天内回复

@Daksha1611 已经在做这个了。

开始于 2026年9月11日。

  • #5313 来自 @Daksha1611 —— 未关闭

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
tooling

调研方向

打开 src/packagedcode/alpine.py,检查 DECLARED_TO_SPDX 以及 issue 中所示的派生 DECLARED_TO_SPDX_SUBS 推导式。确认指定行中的重复键 'as-is' 和 'custom:tu-berlin-2.0',然后进行调整,使每个键只出现一次,且不引入歧义。在修改前后运行提供的 AST 重复键检查(或等效脚本),以确认重复项已消失;当重复键警告消失,且 mapping 行为已明确与预期值保持一致时,即可完成。

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

描述

Description

DECLARED_TO_SPDX in src/packagedcode/alpine.py has two duplicate keys. A dict literal keeps only the last value for a repeated key, so the earlier entry of each pair is dead at import time.

'as-is':

  • line 1619: 'as-is': 'licenseref-scancode-free-unknown',
  • line 1701: 'as-is': 'licenseref-scancode-unknown-license-reference',

'custom:tu-berlin-2.0':

  • line 1690: 'custom:tu-berlin-2.0': 'licenseref-scancode-unknown-license-reference',
  • line 1715: 'custom:tu-berlin-2.0': 'tu-berlin-2.0',

Each of the four entries carries its own comment, so the two pairs look like they were added independently without noticing the collision.

This mapping is turned straight into the substitution table applied to every Alpine package license expression:

DECLARED_TO_SPDX_SUBS = {
    licensing.parse(src, simple=True): licensing.parse(tgt, simple=True)
    for src, tgt in DECLARED_TO_SPDX.items()
}

So which value wins is decided by position in the file rather than by intent. For 'as-is' the surviving value is the less specific licenseref-scancode-unknown-license-reference, and the licenseref-scancode-free-unknown mapping never applies.

How To Reproduce
import ast, collections

src = open('src/packagedcode/alpine.py').read()
for node in ast.walk(ast.parse(src)):
    if isinstance(node, ast.Dict):
        counts = collections.Counter(
            k.value for k in node.keys
            if isinstance(k, ast.Constant) and isinstance(k.value, str)
        )
        for key, n in counts.items():
            if n > 1:
                print(f'line {node.lineno}: duplicate key {key!r} x{n}')
line 1568: duplicate key 'as-is' x2
line 1568: duplicate key 'custom:tu-berlin-2.0' x2
Suggested fix

Drop the dead lines so each key appears once. Which of the two values is actually wanted for each key needs a maintainer decision, since right now it is settled by line order — I have opened a PR that removes the unreachable entries and keeps the currently-winning values, so behaviour does not change.

System configuration
  • What OS are you running on? Linux (x86_64)
  • What version of scancode-toolkit was used? 33.0.0rc1, develop at 5ebebf2
  • What installation method was used to install/run scancode? source checkout
  • Python version: 3.x
主要语言
Python
星标
2.7k
派生
831
平均合并
3 天 4 小时
30 天内合并 PR
7

环境准备

从这里开始

  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 摘要。