aboutcode-org / aboutcode-org/scancode-toolkit

Duplicate LGPL key in rubygems LICENSES_MAPPING makes one mapping unreachable

未關閉
#5,314 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
2.6k
分支
791
平均合併
1 天 12 小時
30 天內合併 PR
5

描述

### Description

`LICENSES_MAPPING` in `src/packagedcode/rubygems.py` defines `'LGPL'` twice, on two consecutive lines (679-680):

```python
'LGPL': 'lgpl',
'LGPL': 'lgpl-2.0-plus',
```

Both are entries of the same dict literal, so the first is discarded and every gem declaring a bare `LGPL` resolves to `lgpl-2.0-plus`.

That is worth a second look on its own: an unversioned `LGPL` declaration does not state a version, and `lgpl-2.0-plus` asserts one. The generic `'LGPL': 'lgpl'` line immediately above looks like the mapping intended for the unversioned case, and the table already has separate explicit entries for the versioned spellings. Either way, which one applies is currently decided by line order rather than intent, and the unreachable line is misleading to read.

### How To Reproduce

```python
import ast, collections

src = open('src/packagedcode/rubygems.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 658: duplicate key 'LGPL' x2
```

And the effective value:

```python
>>> from packagedcode.rubygems import LICENSES_MAPPING
>>> LICENSES_MAPPING['LGPL']
'lgpl-2.0-plus'
```

The `'lgpl'` entry is unreachable.

### Suggested fix

Remove one of the two lines. I have opened a PR that drops the unreachable one and keeps the current result, so nothing changes at runtime. If a bare `LGPL` should instead stay unversioned as `lgpl`, that is a one-word change on top and I am happy to make it.

### 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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。