-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use dataclasses more liberally throughout the codebase (#12571)
- Loading branch information
Showing
19 changed files
with
123 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Convert numerous internal classes to dataclasses for readability and stricter | ||
enforcement of immutability across the codebase. A conservative approach was | ||
taken in selecting which classes to convert. Classes which did not convert | ||
cleanly into a dataclass or were "too complex" (e.g. maintains interconnected | ||
state) were left alone. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
from dataclasses import dataclass | ||
|
||
from pip._vendor.packaging.version import Version | ||
from pip._vendor.packaging.version import parse as parse_version | ||
|
||
from pip._internal.models.link import Link | ||
from pip._internal.utils.models import KeyBasedCompareMixin | ||
|
||
|
||
class InstallationCandidate(KeyBasedCompareMixin): | ||
@dataclass(frozen=True) | ||
class InstallationCandidate: | ||
"""Represents a potential "candidate" for installation.""" | ||
|
||
__slots__ = ["name", "version", "link"] | ||
|
||
name: str | ||
version: Version | ||
link: Link | ||
|
||
def __init__(self, name: str, version: str, link: Link) -> None: | ||
self.name = name | ||
self.version = parse_version(version) | ||
self.link = link | ||
|
||
super().__init__( | ||
key=(self.name, self.version, self.link), | ||
defining_class=InstallationCandidate, | ||
) | ||
|
||
def __repr__(self) -> str: | ||
return ( | ||
f"<InstallationCandidate({self.name!r}, {self.version!r}, {self.link!r})>" | ||
) | ||
object.__setattr__(self, "name", name) | ||
object.__setattr__(self, "version", parse_version(version)) | ||
object.__setattr__(self, "link", link) | ||
|
||
def __str__(self) -> str: | ||
return f"{self.name!r} candidate (version {self.version} at {self.link})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.