chore(lsprotocol): migrate to 2025.0.0 and cleanup artifacts

The changes align the project with the 2025.0.0 lsprotocol
release, removing the old backport and updating type hints
in the protocol hooks to use Sequence where appropriate. The
dist-info and packaging metadata for older lsprotocol
versions are replaced with the new 2025.0.0 artifacts.

- Remove exceptiongroup backport used on Python <3.11
- Use Sequence instead of List in LS protocol hooks
- Replace old dist-info with 2025.0.0 metadata
This commit is contained in:
Christoph Brandau
2026-09-03 08:39:12 +02:00
parent a0a0d38fe5
commit 53ebc5d055
101 changed files with 13838 additions and 7624 deletions
+87 -24
View File
@@ -3,14 +3,17 @@
# for complete details.
from __future__ import annotations
from typing import Iterator
from typing import TYPE_CHECKING
from ._parser import parse_requirement as _parse_requirement
from ._tokenizer import ParserSyntaxError
from .markers import Marker, _normalize_extra_values
from .specifiers import SpecifierSet
from .specifiers import InvalidSpecifier, SpecifierSet
from .utils import canonicalize_name
if TYPE_CHECKING:
from collections.abc import Iterator
__all__ = [
"InvalidRequirement",
"Requirement",
@@ -24,6 +27,8 @@ def __dir__() -> list[str]:
class InvalidRequirement(ValueError):
"""
An invalid requirement was found, users should refer to PEP 508.
.. versionadded:: 16.1
"""
@@ -34,6 +39,18 @@ class Requirement:
URL, and extras. Raises InvalidRequirement on a badly-formed requirement
string.
.. versionadded:: 16.1
.. versionchanged:: 22.0
Added equality (``__eq__``) and hashing (``__hash__``) so requirements
can be compared and stored in sets / dicts.
.. versionchanged:: 23.2
Equality and hashing began canonicalizing requirement names, so
requirements whose names differ only by normalization (e.g.
``Requirement("Foo")`` vs ``Requirement("foo")``) now compare and hash
equal.
Instances are safe to serialize with :mod:`pickle`. They use a stable
format so the same pickle can be loaded in future packaging releases.
@@ -43,6 +60,16 @@ class Requirement:
be unpickled with future releases. Backward compatibility with pickles
from packaging < 26.2 is supported but may be removed in a future
release.
.. versionchanged:: 26.3
The dedicated pickle support introduced in 26.2 did not preserve the
specifier's explicit :attr:`~packaging.specifiers.SpecifierSet.prereleases`
override; it is now included again.
Equality and hashing normalize requirement names, extras, and
equivalent specifiers. The string representation still preserves the
parsed name and extras spelling.
"""
# TODO: Can we test whether something is contained within a requirement?
@@ -50,6 +77,8 @@ class Requirement:
# the thing as well as the version? What about the markers?
# TODO: Can we normalize the name and extra name?
__slots__ = ("extras", "marker", "name", "specifier", "url")
def __init__(self, requirement_string: str) -> None:
try:
parsed = _parse_requirement(requirement_string)
@@ -58,8 +87,11 @@ class Requirement:
self.name: str = parsed.name
self.url: str | None = parsed.url or None
self.extras: set[str] = set(parsed.extras or [])
self.specifier: SpecifierSet = SpecifierSet(parsed.specifier)
self.extras: set[str] = set(parsed.extras)
try:
self.specifier: SpecifierSet = SpecifierSet(parsed.specifier)
except InvalidSpecifier as e:
raise InvalidRequirement(str(e)) from e
self.marker: Marker | None = None
if parsed.marker is not None:
self.marker = Marker.__new__(Marker)
@@ -83,29 +115,44 @@ class Requirement:
if self.marker:
yield f"; {self.marker}"
def __getstate__(self) -> str:
# Return the requirement string for compactness and stability.
# Re-parsed on load to reconstruct all fields.
return str(self)
def __getstate__(self) -> tuple[str, bool | None]:
# Return the requirement string for compactness and stability, paired
# with the specifier's explicit prereleases override, which is not
# captured by the string form. Re-parsed on load to reconstruct all
# other fields.
return (str(self), self.specifier._prereleases)
def __setstate__(self, state: object) -> None:
if isinstance(state, str):
# New format (26.2+): just the requirement string.
try:
tmp = Requirement(state)
except InvalidRequirement as exc:
raise TypeError(f"Cannot restore Requirement from {state!r}") from exc
self.name = tmp.name
self.url = tmp.url
self.extras = tmp.extras
self.specifier = tmp.specifier
self.marker = tmp.marker
return
if isinstance(state, dict):
# Format (26.2): just the requirement string.
requirement_string: str = state
prereleases: bool | None = None
elif (
isinstance(state, tuple)
and len(state) == 2
and isinstance(state[0], str)
and (state[1] is None or isinstance(state[1], bool))
):
# New format (26.3+): (requirement string, specifier prereleases).
requirement_string, prereleases = state
elif isinstance(state, dict) and state.keys() >= set(self.__slots__):
# Old format (packaging <= 26.1, no __slots__): plain __dict__.
self.__dict__.update(state)
for key in self.__slots__:
setattr(self, key, state[key])
return
raise TypeError(f"Cannot restore Requirement from {state!r}")
else:
raise TypeError(f"Cannot restore Requirement from {state!r}")
try:
tmp = Requirement(requirement_string)
except InvalidRequirement as exc:
raise TypeError(f"Cannot restore Requirement from {state!r}") from exc
self.name = tmp.name
self.url = tmp.url
self.extras = tmp.extras
self.specifier = tmp.specifier
self.specifier._prereleases = prereleases
self.marker = tmp.marker
def __str__(self) -> str:
return "".join(self._iter_parts(self.name))
@@ -114,15 +161,31 @@ class Requirement:
return f"<{self.__class__.__name__}({str(self)!r})>"
def __hash__(self) -> int:
return hash(tuple(self._iter_parts(canonicalize_name(self.name))))
# Mirror __eq__ by hashing the canonical specifier object rather than
# its raw string. ``_iter_parts`` yields ``str(self.specifier)``, which
# is non-canonical, so trailing-zero-equivalent requirements such as
# ``foo==1.0.0`` and ``foo==1.0.0.0`` (which compare equal) would
# otherwise hash differently, breaking the hash/__eq__ invariant.
return hash(
(
canonicalize_name(self.name),
frozenset(canonicalize_name(e) for e in self.extras),
self.specifier,
self.url,
self.marker,
)
)
def __eq__(self, other: object) -> bool:
if not isinstance(other, Requirement):
return NotImplemented
# Extras must be normalized before comparison as per PEP 685.
self_extras = frozenset(canonicalize_name(e) for e in self.extras)
other_extras = frozenset(canonicalize_name(e) for e in other.extras)
return (
canonicalize_name(self.name) == canonicalize_name(other.name)
and self.extras == other.extras
and self_extras == other_extras
and self.specifier == other.specifier
and self.url == other.url
and self.marker == other.marker