AdithyaSK's picture
AdithyaSK HF Staff
Publish 100 swe_next Harbor tasks
d40299b verified
|
Raw History Blame Contribute Delete
1.75 kB
## `parse_tag()` raises `ValueError` instead of `InvalidTag` for tags with wrong number of components
### Description
Calling `parse_tag()` with a tag string that doesn't have exactly three hyphen-separated components (interpreter, ABI, platform) raises a raw `ValueError` from Python's tuple unpacking instead of the documented `InvalidTag` exception.
For example:
```python
from packaging import tags
# Tag with only two components (missing platform)
tags.parse_tag("py3-none")
# Tag with four components (extra field)
tags.parse_tag("py3-none-any-extra")
```
Running either of these raises:
```
ValueError: not enough values to unpack (expected 3, got 2)
```
or
```
ValueError: too many values to unpack (expected 3)
```
The error originates from the internal tuple unpacking `interpreters, abis, platforms = component_parts` in `parse_tag()` in `src/packaging/tags.py`.
### Expected behavior
Both inputs should raise `tags.InvalidTag` (a subclass of `ValueError`) with a message indicating the tag must have exactly three components, consistent with how empty tag components are already handled. Code that catches `InvalidTag` to handle malformed tags should not need to also catch the bare `ValueError`.
### Actual behavior
A plain `ValueError` is raised directly from the tuple unpacking, bypassing the `InvalidTag` public error contract. Any caller that catches `tags.InvalidTag` to validate tag strings will miss these malformed inputs.
Work in `/workspace`. Submit your fix in the existing Python source files under `src/packaging`. Preserve the other public behavior. The environment is offline; dependencies are preinstalled. Grading runs the repository's test suite in a fresh environment, using your submitted source files.