Skip to content

Fix requirements parser crash on multiple extras groups - #11299

Open
adityajai119 wants to merge 1 commit into
python-poetry:mainfrom
adityajai119:fix-requirements-parser-multiple-extras
Open

adityajai119 wants to merge 1 commit into
python-poetry:mainfrom
adityajai119:fix-requirements-parser-multiple-extras

Conversation

@adityajai119

Copy link
Copy Markdown

Summary

RequirementsParser.parse() used requirement.split("[") to strip a trailing extras group. A requirement containing more than one [ (for example demo[a][b]) made that unpack raise ValueError: too many values to unpack (expected 2) instead of the documented Invalid dependency specification error.

The parser now splits on the first [ only and reports an invalid specification when another bracket group remains.

Test

  • Added test_parse_rejects_requirement_with_multiple_extras_groups.
  • pytest tests/utils/test_dependency_specification.py: 24 passed.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/poetry/utils/dependency_specification.py" line_range="84" />
<code_context>
             extras = [e.strip() for e in extras_m.group(1).split(",")]
-            requirement, _ = requirement.split("[")
+            name, _, remainder = requirement.partition("[")
+            if "[" in remainder:
+                raise ValueError(f"Invalid dependency specification: {requirement}")
+            requirement = name
</code_context>
<issue_to_address>
**Invalid extras raise wrong error**

When multiple extras groups are followed by a version constraint or suffix, such as `demo[a][b]>=1.0` or `demo[a][b]@1.0.0`, `parse` skips the trailing-extras check, so `_parse_simple` matches the final extras group and `name.split("[")` raises `ValueError: too many values to unpack` instead of the documented invalid-specification error.

Run the multiple-bracket validation on the extras portion even when a version suffix is present.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/poetry/utils/dependency_specification.py:84


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant