Skip to content

Commit

Permalink
create a "NormalizedLicenseExpression" type
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Sep 13, 2024
1 parent e469b7e commit e699391
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/packaging/licenses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down

0 comments on commit e699391

Please sign in to comment.