pep440: some minor refactoring, mostly around error types (#780)

This PR does a bit of refactoring to the pep440 crate, and in
particular around the erorr types. This PR is meant to be a precursor
to another PR that does some surgery (both in parsing and in `Version`
representation) that benefits somewhat from this refactoring.

As usual, please review commit-by-commit.
This commit is contained in:
Andrew Gallant 2024-01-04 12:28:36 -05:00 committed by GitHub
parent 1cc3250e76
commit d7c9b151fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 710 additions and 262 deletions

View file

@ -702,7 +702,7 @@ fn parse_specifier(
end: usize,
) -> Result<VersionSpecifier, Pep508Error> {
VersionSpecifier::from_str(buffer).map_err(|err| Pep508Error {
message: Pep508ErrorSource::String(err),
message: Pep508ErrorSource::String(err.to_string()),
start,
len: end - start,
input: cursor.to_string(),
@ -1262,7 +1262,7 @@ mod tests {
assert_err(
r#"numpy >=1.1.*"#,
indoc! {"
Operator >= must not be used in version ending with a star
Operator >= cannot be used with a wildcard version specifier
numpy >=1.1.*
^^^^^^^"
},
@ -1442,7 +1442,7 @@ mod tests {
assert_err(
"name==",
indoc! {"
Missing version
Unexpected end of version specifier, expected version
name==
^^"
},
@ -1466,7 +1466,7 @@ mod tests {
assert_err(
"name >= 1.0 #",
indoc! {"
Trailing `#` not allowed
Trailing `#` is not allowed
name >= 1.0 #
^^^^^^^^"
},

View file

@ -783,7 +783,7 @@ impl MarkerExpression {
let compatible = python_versions.iter().any(|r_version| {
// operator and right hand side make the specifier and in this case the
// right hand is `python_version` so changes every iteration
match VersionSpecifier::new(operator.clone(), r_version.clone(), false) {
match VersionSpecifier::new(operator, r_version.clone(), false) {
Ok(specifier) => specifier.contains(&l_version),
Err(_) => true,
}