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

@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use serde::{de, Deserialize, Deserializer, Serialize};
use pep440_rs::{Pep440Error, VersionSpecifiers};
use pep440_rs::{VersionSpecifiers, VersionSpecifiersParseError};
use pep508_rs::{Pep508Error, Requirement};
use puffin_warnings::warn_user_once;
@ -99,7 +99,7 @@ impl From<LenientRequirement> for Requirement {
pub struct LenientVersionSpecifiers(VersionSpecifiers);
impl FromStr for LenientVersionSpecifiers {
type Err = Pep440Error;
type Err = VersionSpecifiersParseError;
fn from_str(input: &str) -> Result<Self, Self::Err> {
Ok(Self(parse_with_fixups(input, "version specifier")?))

View file

@ -7,7 +7,7 @@ use mailparse::{MailHeaderMap, MailParseError};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use pep440_rs::{Pep440Error, Version, VersionSpecifiers};
use pep440_rs::{Version, VersionSpecifiers, VersionSpecifiersParseError};
use pep508_rs::{Pep508Error, Requirement};
use puffin_normalize::{ExtraName, InvalidNameError, PackageName};
@ -63,7 +63,7 @@ pub enum Error {
Pep440VersionError(String),
/// Invalid VersionSpecifier
#[error(transparent)]
Pep440Error(#[from] Pep440Error),
Pep440Error(#[from] VersionSpecifiersParseError),
/// Invalid Requirement
#[error(transparent)]
Pep508Error(#[from] Pep508Error),