-
Notifications
You must be signed in to change notification settings - Fork 469
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
Commits on Jan 4, 2024
-
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.
Configuration menu - View commit details
-
Copy full SHA for c3fbbf0 - Browse repository at this point
Copy the full SHA c3fbbf0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1615a83 - Browse repository at this point
Copy the full SHA 1615a83View commit details -
This moves LocalSegment and PreRelease after Version, and also keeps their impl blocks grouped together. No code is changed here.
Configuration menu - View commit details
-
Copy full SHA for b0fbe40 - Browse repository at this point
Copy the full SHA b0fbe40View commit details -
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.)
Configuration menu - View commit details
-
Copy full SHA for cc6d12d - Browse repository at this point
Copy the full SHA cc6d12dView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 33450a8 - Browse repository at this point
Copy the full SHA 33450a8View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 77fefdf - Browse repository at this point
Copy the full SHA 77fefdfView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 872865b - Browse repository at this point
Copy the full SHA 872865bView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 3e726ff - Browse repository at this point
Copy the full SHA 3e726ffView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 0fbf72d - Browse repository at this point
Copy the full SHA 0fbf72dView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 63da3d1 - Browse repository at this point
Copy the full SHA 63da3d1View commit details