]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
recipetool: Do not use mutable default arguments in Python
authorStefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Thu, 14 Apr 2022 11:06:35 +0000 (13:06 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 19 Apr 2022 13:14:01 +0000 (14:14 +0100)
Remove mutable default arguments in Python because they can lead to all
sorts of nasty and horrible bugs.

https://florimond.dev/en/posts/2018/08/python-mutable-defaults-are-the-source-of-all-evil/

Revert `recipetool: Change default paramter fallback_licenses of
function split_pkg_licenses from None to []` and instead check
fallback_licenses before use.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/recipetool/create.py

index 220465ed2f48cb4909892bdfc9b4cc5e6cd11257..824ac6350d91ecdecc5955d1228d981d38c9d79b 100644 (file)
@@ -1235,7 +1235,7 @@ def guess_license(srctree, d):
 
     return licenses
 
-def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=[], pn='${PN}'):
+def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=None, pn='${PN}'):
     """
     Given a list of (license, path, md5sum) as returned by guess_license(),
     a dict of package name to path mappings, write out a set of
@@ -1258,7 +1258,7 @@ def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=[], pn='
     for pkgname in packages:
         # Assume AND operator between license files
         license = ' & '.join(list(set(pkglicenses.get(pkgname, ['Unknown'])))) or 'Unknown'
-        if license == 'Unknown' and pkgname in fallback_licenses:
+        if license == 'Unknown' and fallback_licenses and pkgname in fallback_licenses:
             license = fallback_licenses[pkgname]
         licenses = tidy_licenses(license)
         license = ' & '.join(licenses)