Skip to content

Commit 4e514db

Browse files
committed
[WIP] surface LegacyVersion deprecation warnings
1 parent 42b19ab commit 4e514db

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/pip/_vendor/packaging/specifiers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,17 @@ class LegacySpecifier(_IndividualSpecifier):
252252
def __init__(self, spec: str = "", prereleases: Optional[bool] = None) -> None:
253253
super().__init__(spec, prereleases)
254254

255-
warnings.warn(
256-
"Creating a LegacyVersion has been deprecated and will be "
257-
"removed in the next major release",
258-
DeprecationWarning,
255+
from pip._internal.utils.deprecation import deprecated
256+
257+
deprecated(
258+
reason=(f"This form of version specifier ({spec}) has been deprecated."),
259+
replacement="use PEP 440 compatible version specifiers",
260+
gone_in="23.2",
259261
)
260262

261263
def _coerce_version(self, version: UnparsedVersion) -> LegacyVersion:
262264
if not isinstance(version, LegacyVersion):
263-
version = LegacyVersion(str(version))
265+
version = LegacyVersion(str(version), silence_deprecation_warning=True)
264266
return version
265267

266268
def _compare_equal(self, prospective: LegacyVersion, spec: str) -> bool:

src/pip/_vendor/packaging/version.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,22 @@ def __ne__(self, other: object) -> bool:
104104

105105

106106
class LegacyVersion(_BaseVersion):
107-
def __init__(self, version: str) -> None:
107+
def __init__(
108+
self,
109+
version: str,
110+
silence_deprecation_warning: bool = False,
111+
) -> None:
108112
self._version = str(version)
109113
self._key = _legacy_cmpkey(self._version)
110114

111-
warnings.warn(
112-
"Creating a LegacyVersion has been deprecated and will be "
113-
"removed in the next major release",
114-
DeprecationWarning,
115-
)
115+
if not silence_deprecation_warning:
116+
from pip._internal.utils.deprecation import deprecated
117+
118+
deprecated(
119+
reason=(f"This form of version ({version}) has been deprecated."),
120+
replacement="use PEP 440 compatible versions",
121+
gone_in="23.2",
122+
)
116123

117124
def __str__(self) -> str:
118125
return self._version

0 commit comments

Comments
 (0)