Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Wellshh
Copy link
Contributor

@Wellshh Wellshh commented Oct 16, 2025

Pull Request Check List

Resolves: #10586

  • Added tests for changed code.
  • Updated documentation for changed code.

Tests:

  • Add parameterized tests for removing packages from nested dependency groups in both PEP735 and legacy poetry styles

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 16, 2025

Reviewer's Guide

Fix removal errors when nested include-group constructs are used by filtering out non-string requirement entries in the remove command logic and add parameterized tests covering both PEP 735 and legacy group syntax to verify proper pyproject updates.

Class diagram for updated remove command logic

classDiagram
    class RemoveCommand {
        +handle() int
        -_remove_packages(packages, standard_section, poetry_section)
    }
    class Dependency {
        +create_from_pep_508(requirement)
        +name
    }
    RemoveCommand --> Dependency: uses
Loading

Flow diagram for package removal with nested include-group constructs

flowchart TD
    A["Start package removal"] --> B["Read pyproject content"]
    B --> C["Get dependency groups and poetry groups"]
    C --> D["Iterate over packages to remove"]
    D --> E["For each requirement in standard section"]
    E --> F{Is requirement a string?}
    F -- Yes --> G["Check if requirement name matches package"]
    G -- Match --> H["Remove requirement"]
    G -- No match --> I["Continue"]
    F -- No --> I
    H --> J["Add package to removed set"]
    I --> D
    J --> D
    D --> K["Finish"]
Loading

File-Level Changes

Change Details Files
Guard string requirements in removal logic to handle nested groups
  • Add isinstance(requirement, str) check before parsing requirements
  • Prevent passing dict items (include-group entries) to Dependency.create_from_pep_508
src/poetry/console/commands/remove.py
Add tests for nested dependency group removal covering PEP 735 and legacy syntax
  • Parametrize test with pep_735 flag
  • Setup nested include-group definitions in pyproject.toml
  • Assert correct removal of dependencies and group entries in both syntaxes
tests/console/commands/test_remove.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

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

## Individual Comments

### Comment 1
<location> `tests/console/commands/test_remove.py:739-691` </location>
<code_context>
+    pyproject = app.poetry.file.read()
+    pyproject = cast("dict[str, Any]", pyproject)
+    content = pyproject["tool"]["poetry"]
+    assert "foo" not in content["dependencies"]
+
+    if pep_735:
+        assert "bar" not in pyproject["dependency-groups"]
+        assert any("baz" in dep for dep in pyproject["dependency-groups"]["foobar"])
</code_context>

<issue_to_address>
**suggestion (testing):** Test could be improved by verifying side effects on installed packages.

Please add an assertion to confirm that 'foo' is removed from the 'installed' repository after the operation.

Suggested implementation:

```python
    pyproject = app.poetry.file.read()
    pyproject = cast("dict[str, Any]", pyproject)
    content = pyproject["tool"]["poetry"]
    assert "foo" not in content["dependencies"]

    # Assert 'foo' is not present in the installed repository
    installed_packages = [pkg.name for pkg in app.poetry.repository.installed()]
    assert "foo" not in installed_packages

```

If `app.poetry.repository.installed()` does not exist or uses a different API, you may need to adjust the method to retrieve the list of installed packages according to your Poetry test setup.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@radoering radoering force-pushed the fix/cmd-remove-handle-include-groups branch from 887fb04 to 3d9a787 Compare October 26, 2025 17:18
@radoering radoering changed the title fix error of removing packages if nested groups (include-group) are u… fix error of removing packages if nested groups (include-group) are used in pep735 style Oct 26, 2025
@radoering radoering merged commit 6f31f56 into python-poetry:main Oct 26, 2025
63 checks passed
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

poetry remove crashes when removing a package from a legacy dependency group (PEP 735) containing include-group

2 participants