From 8738ed39f09d169b85551c43ea4f11ed5dd80f7b Mon Sep 17 00:00:00 2001 From: Richard Si Date: Tue, 30 Apr 2024 17:35:01 -0400 Subject: [PATCH] Convert FrozenRequirement --- src/pip/_internal/operations/freeze.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/pip/_internal/operations/freeze.py b/src/pip/_internal/operations/freeze.py index 35445684514..a2e2c970749 100644 --- a/src/pip/_internal/operations/freeze.py +++ b/src/pip/_internal/operations/freeze.py @@ -1,9 +1,10 @@ import collections import logging import os +from dataclasses import dataclass, field from typing import Container, Dict, Generator, Iterable, List, NamedTuple, Optional, Set -from pip._vendor.packaging.utils import canonicalize_name +from pip._vendor.packaging.utils import NormalizedName, canonicalize_name from pip._vendor.packaging.version import Version from pip._internal.exceptions import BadCommand, InstallationError @@ -217,19 +218,16 @@ def _get_editable_info(dist: BaseDistribution) -> _EditableInfo: ) +@dataclass(frozen=True) class FrozenRequirement: - def __init__( - self, - name: str, - req: str, - editable: bool, - comments: Iterable[str] = (), - ) -> None: - self.name = name - self.canonical_name = canonicalize_name(name) - self.req = req - self.editable = editable - self.comments = comments + name: str + req: str + editable: bool + comments: Iterable[str] = field(default_factory=tuple) + + @property + def canonical_name(self) -> NormalizedName: + return canonicalize_name(self.name) @classmethod def from_dist(cls, dist: BaseDistribution) -> "FrozenRequirement":