|
| 1 | +Surface LegacyVersion and LegacySpecifier deprecation warnings |
| 2 | +as pip deprecation warnings. |
| 3 | + |
| 4 | +--- |
| 5 | + src/pip/_vendor/packaging/specifiers.py | 12 +++++++----- |
| 6 | + src/pip/_vendor/packaging/version.py | 19 +++++++++++++------ |
| 7 | + 2 files changed, 20 insertions(+), 11 deletions(-) |
| 8 | + |
| 9 | +diff --git a/src/pip/_vendor/packaging/specifiers.py b/src/pip/_vendor/packaging/specifiers.py |
| 10 | +index 0e218a6f9f7..b0a1cee288b 100644 |
| 11 | +--- a/src/pip/_vendor/packaging/specifiers.py |
| 12 | ++++ b/src/pip/_vendor/packaging/specifiers.py |
| 13 | +@@ -252,15 +252,18 @@ class LegacySpecifier(_IndividualSpecifier): |
| 14 | + def __init__(self, spec: str = "", prereleases: Optional[bool] = None) -> None: |
| 15 | + super().__init__(spec, prereleases) |
| 16 | + |
| 17 | +- warnings.warn( |
| 18 | +- "Creating a LegacyVersion has been deprecated and will be " |
| 19 | +- "removed in the next major release", |
| 20 | +- DeprecationWarning, |
| 21 | ++ from pip._internal.utils.deprecation import deprecated |
| 22 | ++ |
| 23 | ++ deprecated( |
| 24 | ++ reason=(f"This form of version specifier ({spec}) has been deprecated."), |
| 25 | ++ replacement="use PEP 440 compatible version specifiers", |
| 26 | ++ gone_in="23.3", |
| 27 | ++ issue=12063, |
| 28 | + ) |
| 29 | + |
| 30 | + def _coerce_version(self, version: UnparsedVersion) -> LegacyVersion: |
| 31 | + if not isinstance(version, LegacyVersion): |
| 32 | +- version = LegacyVersion(str(version)) |
| 33 | ++ version = LegacyVersion(str(version), silence_deprecation_warning=True) |
| 34 | + return version |
| 35 | + |
| 36 | + def _compare_equal(self, prospective: LegacyVersion, spec: str) -> bool: |
| 37 | +diff --git a/src/pip/_vendor/packaging/version.py b/src/pip/_vendor/packaging/version.py |
| 38 | +index de9a09a4ed3..cc68ed67424 100644 |
| 39 | +--- a/src/pip/_vendor/packaging/version.py |
| 40 | ++++ b/src/pip/_vendor/packaging/version.py |
| 41 | +@@ -104,15 +104,23 @@ def __ne__(self, other: object) -> bool: |
| 42 | + |
| 43 | + |
| 44 | + class LegacyVersion(_BaseVersion): |
| 45 | +- def __init__(self, version: str) -> None: |
| 46 | ++ def __init__( |
| 47 | ++ self, |
| 48 | ++ version: str, |
| 49 | ++ silence_deprecation_warning: bool = False, |
| 50 | ++ ) -> None: |
| 51 | + self._version = str(version) |
| 52 | + self._key = _legacy_cmpkey(self._version) |
| 53 | + |
| 54 | +- warnings.warn( |
| 55 | +- "Creating a LegacyVersion has been deprecated and will be " |
| 56 | +- "removed in the next major release", |
| 57 | +- DeprecationWarning, |
| 58 | +- ) |
| 59 | ++ if not silence_deprecation_warning: |
| 60 | ++ from pip._internal.utils.deprecation import deprecated |
| 61 | ++ |
| 62 | ++ deprecated( |
| 63 | ++ reason=(f"This form of version ({version}) has been deprecated."), |
| 64 | ++ replacement="use PEP 440 compatible versions", |
| 65 | ++ gone_in="23.3", |
| 66 | ++ issue=12063, |
| 67 | ++ ) |
| 68 | + |
| 69 | + def __str__(self) -> str: |
| 70 | + return self._version |
0 commit comments