uv/crates/uv-pep440/src
Jacob Woliver f5c3601445
Better error message for version specifier with missing operator (#13803)
## Summary

When missing an operator for version parsing, it would give an error
that was hard to know how to fix if you were not familiar with version
specifiers / PEP-440:

```
Unexpected end of version specifier, expected operator
```

Now, it will attempt to provide a more useful hint if it can parse the
version from the remaining scanner:

```
Unexpected end of version specifier, expected operator (did you mean "==3.12"?)
```
## Test Plan

Unit tests in `version_specifier.rs` were added/updated for the
following cases:
- `test_parse_specifier_missing_operator_error`
- `test_parse_specifier_missing_operator_invalid_version_error`
- `test_invalid_word`
- `test_invalid_specifier`
- `error_message_version_specifiers_parse_error`

A test in `edit.rs` for failing to parse the `pyproject.toml` when using
`add` was also included to match the request in the original issue:
- `add_invalid_requires_python`

I didn't add cases where no version specifier is provided because it
seemed like it doesn't get to the point of parsing in that case, so it
should not happen.


## Reference

Fixes #13126

---------

Co-authored-by: Jacob Woliver <jacob@jmw.sh>
Co-authored-by: konstin <konstin@mailbox.org>
2025-06-03 19:18:19 +00:00
..
lib.rs Bump MSRV to 1.85 and Edition 2024 (#13516) 2025-05-18 19:38:43 -04:00
version.rs Optimize Version display (#13643) 2025-05-26 15:17:07 +02:00
version_ranges.rs Move `LowerBound` and `UpperBound` structs in `uv-pep440` (#11950) 2025-03-04 12:35:16 -05:00
version_specifier.rs Better error message for version specifier with missing operator (#13803) 2025-06-03 19:18:19 +00:00