Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 10 commits into from
Jan 4, 2024

Commits on Jan 4, 2024

  1. pep440: add comment describing experimental data

    I'll like expand this comment a little bit in subsequent commits, but I
    felt like this was useful to put in the beginning of this patch series
    to "set the stage." That is, this data will motivate some of the
    optimizations we'll do for version parsing, version representation and
    comparisons.
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    c3fbbf0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1615a83 View commit details
    Browse the repository at this point in the history
  3. pep440: move around move code

    This moves LocalSegment and PreRelease after Version, and also keeps
    their impl blocks grouped together.
    
    No code is changed here.
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    b0fbe40 View commit details
    Browse the repository at this point in the history
  4. pep440: add regression test for non-ASCII version specifier

    It turns out that the current parser permits non-ASCII whitespace in
    places. We can be sneaky here to cause the existing implementation to
    produce incorrect offsets.
    
    The core issue here is that `unicode-width` is used to compute codepoint
    offsets, but its actual purpose is to compute the *visual width* of a
    codepoint that has been rendered. Some codepoints use more than 1 unit
    of visual width.
    
    While this establishes a mismatch between the implementation and the
    documented behavior of `Pep440Error`, we will also address this by
    switching to byte offsets instead of codepoint offsets. (Codepoint
    offsets are almost never what you want.)
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    cc6d12d View commit details
    Browse the repository at this point in the history
  5. pep440: switch error to use byte offsets

    We still use unicode-width, but only when rendering the error message.
    
    We also add the error message itself to the Display impl.
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    33450a8 View commit details
    Browse the repository at this point in the history
  6. pep440: rejigger error type

    This error type was only be used when one attempted to parse a string as
    a `VersionSpecifiers`. We'll want to introduce more structured error
    types for parsing `Version` and `VersionSpecifier` as well, so renaming
    the error type helps make room for that.
    
    We also make the error type opaque. Nothing (in puffin at least) seemed
    to need its internals. We can always add accessor methods in the future
    if something else needs it. It's overall rare to need to expose the
    entire internal representation of an error type.
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    77fefdf View commit details
    Browse the repository at this point in the history
  7. pep440: move VersionSpecifiersError to version_specifiers module

    Since it's specifier to version specifier parsing, it makes sense to
    have it live with the corresponding type. Putting it in lib.rs I think
    makes it seem like an error type that applies to other things as well.
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    872865b View commit details
    Browse the repository at this point in the history
  8. pep440: use structured errors for version specifiers

    This smoothes out the error handling to using something a bit more
    structured. I did this because I intend to do the same for Version
    (eventually), and it seems good to be consistent. It also lets us nest
    errors a bit more easily and scrutinize the different error classes at a
    glance.
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    3e726ff View commit details
    Browse the repository at this point in the history
  9. pep440: add more boxing

    This makes the top-level error type small, just as the others we added
    in the previous commit are. This was specifically flagged by Clippy.
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    0fbf72d View commit details
    Browse the repository at this point in the history
  10. pep440: add tests for human visible error messages

    Prior to the refactoring in previous commits, tests were generally
    written against the rendered error message instead of the structured
    message. This was in part because many of the error types themselves
    were just a `String`, but also to explicitly test what an end user
    actually sees. That's valuable.
    
    While we keep most of the tests as rewritten to target the new
    structured error representation, we add some new tests that captures the
    value of testing the messages than humans will actually see.
    BurntSushi committed Jan 4, 2024
    Configuration menu
    Copy the full SHA
    63da3d1 View commit details
    Browse the repository at this point in the history