From e6993918b32f78e80e6e18d80b559dee74bfc9e3 Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Fri, 13 Sep 2024 12:08:01 -0400 Subject: [PATCH] create a "NormalizedLicenseExpression" type --- src/packaging/licenses/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/packaging/licenses/__init__.py b/src/packaging/licenses/__init__.py index 7f09dd96..92cbbb6b 100644 --- a/src/packaging/licenses/__init__.py +++ b/src/packaging/licenses/__init__.py @@ -32,11 +32,14 @@ from __future__ import annotations import re +from typing import NewType from packaging.licenses.spdx import EXCEPTIONS, LICENSES license_ref_allowed = re.compile("^[A-Za-z0-9.-]*$") +NormalizedLicenseExpression = NewType("NormalizedLicenseExpression", str) + class InvalidLicenseExpression(ValueError): """Raised when a license-expression string @@ -48,11 +51,11 @@ class InvalidLicenseExpression(ValueError): """ -def normalize_license_expression(raw_license_expression: str) -> str | None: +def normalize_license_expression( + raw_license_expression: str, +) -> str | NormalizedLicenseExpression: if raw_license_expression == "": - message = ( - f"Invalid license expression: {raw_license_expression}" - ) + message = f"Invalid license expression: {raw_license_expression}" raise InvalidLicenseExpression(message) license_refs = {