Skip to content

Commit dc5e35e

Browse files
Fix outdated documentation on Requires-Python (#8679)
## Summary Closes #8675.
1 parent e5b8cdb commit dc5e35e

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

crates/uv-resolver/src/requires_python.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,16 @@ pub enum RequiresPythonError {
1919

2020
/// The `Requires-Python` requirement specifier.
2121
///
22-
/// We treat `Requires-Python` as a lower bound. For example, if the requirement expresses
23-
/// `>=3.8, <4`, we treat it as `>=3.8`. `Requires-Python` itself was intended to enable
24-
/// packages to drop support for older versions of Python without breaking installations on
25-
/// those versions, and packages cannot know whether they are compatible with future, unreleased
26-
/// versions of Python.
27-
///
2822
/// See: <https://packaging.python.org/en/latest/guides/dropping-older-python-versions/>
2923
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
3024
pub struct RequiresPython {
3125
/// The supported Python versions as provides by the user, usually through the `requires-python`
3226
/// field in `pyproject.toml`.
3327
///
34-
/// For a workspace, it's the union of all `requires-python` values in the workspace. If no
28+
/// For a workspace, it's the intersection of all `requires-python` values in the workspace. If no
3529
/// bound was provided by the user, it's greater equal the current Python version.
3630
specifiers: VersionSpecifiers,
37-
/// The lower and upper bounds of `specifiers`.
31+
/// The lower and upper bounds of the given specifiers.
3832
range: RequiresPythonRange,
3933
}
4034

@@ -108,7 +102,7 @@ impl RequiresPython {
108102
}))
109103
}
110104

111-
/// Narrow the [`RequiresPython`] to the given version, if it's stricter than the current target.
105+
/// Narrow the [`RequiresPython`] by computing the intersection with the given range.
112106
pub fn narrow(&self, range: &RequiresPythonRange) -> Option<Self> {
113107
let lower = if range.0 >= self.range.0 {
114108
Some(&range.0)
@@ -228,17 +222,35 @@ impl RequiresPython {
228222
}
229223

230224
/// Returns `true` if the `Requires-Python` is compatible with the given version.
225+
///
226+
/// N.B. This operation should primarily be used when evaluating compatibility of Python
227+
/// versions against the user's own project. For example, if the user defines a
228+
/// `requires-python` in a `pyproject.toml`, this operation could be used to determine whether
229+
/// a given Python interpreter is compatible with the user's project.
231230
pub fn contains(&self, version: &Version) -> bool {
232231
let version = version.only_release();
233232
self.specifiers.contains(&version)
234233
}
235234

236-
/// Returns `true` if the `Requires-Python` is compatible with the given version specifiers.
235+
/// Returns `true` if the `Requires-Python` is contained by the given version specifiers.
236+
///
237+
/// In this context, we treat `Requires-Python` as a lower bound. For example, if the
238+
/// requirement expresses `>=3.8, <4`, we treat it as `>=3.8`. `Requires-Python` itself was
239+
/// intended to enable packages to drop support for older versions of Python without breaking
240+
/// installations on those versions, and packages cannot know whether they are compatible with
241+
/// future, unreleased versions of Python.
242+
///
243+
/// The specifiers are considered to "contain" the `Requires-Python` if the specifiers are
244+
/// compatible with all versions in the `Requires-Python` range (i.e., have a _lower_ lower
245+
/// bound).
237246
///
238247
/// For example, if the `Requires-Python` is `>=3.8`, then `>=3.7` would be considered
239248
/// compatible, since all versions in the `Requires-Python` range are also covered by the
240249
/// provided range. However, `>=3.9` would not be considered compatible, as the
241250
/// `Requires-Python` includes Python 3.8, but `>=3.9` does not.
251+
///
252+
/// N.B. This operation should primarily be used when evaluating the compatibility of a
253+
/// project's `Requires-Python` specifier against a dependency's `Requires-Python` specifier.
242254
pub fn is_contained_by(&self, target: &VersionSpecifiers) -> bool {
243255
let Ok(target) = VersionRangesSpecifier::from_release_specifiers(target) else {
244256
return false;

0 commit comments

Comments
 (0)