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

Open Beginner friendly
#5,405 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@omisha123 is already working on this.

Since Nov 7, 2026.

  • #5451 by @omisha123 — open

Assessment

Difficulty
2/5
Estimated time
Half a day
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
tooling

Research direction

Start with item 1 in src/licensedcode/required_phrases.py near line 205, where the license_expression property evaluates self.rule.license_expression without returning it, and check how other properties in that class read their values. Item 2 is in src/commoncode/command.py around line 319, where find_in_path evaluates searchable_paths() at import time. Run a small script that changes PATH after import to reproduce it. Item 3 needs a maintainer decision on the intended values in src/packagedcode/rubygems.py and src/packagedcode/alpine.py, so leave it alone unless the thread settles it. Done means the fixed properties return the expected values and the relevant tests pass.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
2.7k
Forks
871
Avg merge
1d 10h
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aboutcode-org/scancode-toolkit

All issues in aboutcode-org/scancode-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.