Skip to content

Commit cb0604d

Browse files
committed
fix edge case where pypi license: null causes a crash (#81)
1 parent d0dadc8 commit cb0604d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

licensecheck/packageinfo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def getPackageInfoPypi(requirement: ucstr) -> PackageInfo:
8686
author=_pkgMetadataGet(info, "author"),
8787
size=size,
8888
license=ucstr(
89-
licenseClassifier if licenseClassifier != UNKNOWN else info.get("license", UNKNOWN)
89+
licenseClassifier
90+
if licenseClassifier != UNKNOWN
91+
else info.get("license", UNKNOWN) or UNKNOWN
9092
),
9193
)
9294
except KeyError as error:

licensecheck/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ class ucstr(str):
1111

1212
__slots__ = ()
1313

14-
def __new__(cls, v: str) -> ucstr:
14+
def __new__(cls, v: str|None) -> ucstr:
1515
"""Create a new ucstr from a str.
1616
1717
:param str v: string to cast
1818
:return ucstr: uppercase string.
1919
"""
20+
if v is None:
21+
return ucstr("")
2022
return super().__new__(cls, v.upper())
2123

2224

0 commit comments

Comments
 (0)