Repository navigation
Conversation
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/poetry/console/commands/remove.py" line_range="251" />
<code_context>
# 2. Legacy: [tool.poetry.group.<name>] include-groups = [...]
poetry_content = content.get("tool", {}).get("poetry", {})
if "group" in poetry_content:
+ normalized_group_name = canonicalize_name(group_name)
groups_to_remove = []
for group_key, group_content in poetry_content["group"].items():
</code_context>
<issue_to_address>
**Mixed-format references remain dangling**
When a legacy group is removed while a PEP 735 group references it using a canonically equivalent spelling, the PEP 735 cleanup branch still compares `item.get("include-group")` to `group_name` literally. Removing a legacy group keyed as `lint_tools` therefore leaves a PEP 735 reference spelled `lint-tools` in `[dependency-groups]`, and the project fails to load on a later command.
Normalize the PEP 735 `include-group` value and the removed group name before comparing them.
</issue_to_address>
### Comment 2
<location path="src/poetry/console/commands/remove.py" line_range="259" />
<code_context>
+ name
+ for name in include_groups
+ if isinstance(name, str)
+ and canonicalize_name(name) == normalized_group_name
+ ]
+ if not to_remove:
</code_context>
<issue_to_address>
**Surviving group references disappear**
When a legacy group is removed while the same canonical group remains under a differently spelled key in `[dependency-groups]`, `_remove_references_to_group` removes the legacy include even though the PEP 735 table still defines the same canonical group, so the including group loses dependencies from that surviving group.
Before removing a reference, preserve it when a canonically equivalent group remains defined in either section.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and if the normalized-name match is too broad, running remove could delete an include-groups entry from the project’s pyproject.toml. Reverting the code would not restore that file, though the affected configuration is bounded and can be restored manually.
Blocking findings: src/poetry/console/commands/remove.py:251, src/poetry/console/commands/remove.py:259
| name | ||
| for name in include_groups | ||
| if isinstance(name, str) | ||
| and canonicalize_name(name) == normalized_group_name |
There was a problem hiding this comment.
🟡 Medium · Surviving group references disappear
When a legacy group is removed while the same canonical group remains under a differently spelled key in [dependency-groups], _remove_references_to_group removes the legacy include even though the PEP 735 table still defines the same canonical group, so the including group loses dependencies from that surviving group.
Before removing a reference, preserve it when a canonically equivalent group remains defined in either section.
Prompt for AI agents
In `src/poetry/console/commands/remove.py` at line 259:
**Surviving group references disappear**
When a legacy group is removed while the same canonical group remains under a differently spelled key in `[dependency-groups]`, `_remove_references_to_group` removes the legacy include even though the PEP 735 table still defines the same canonical group, so the including group loses dependencies from that surviving group.
Before removing a reference, preserve it when a canonically equivalent group remains defined in either section.`poetry remove` deletes a dependency group that became empty and then
cleans up references to it in other groups. For the legacy
`[tool.poetry.group.<name>] include-groups` section that comparison was a
literal string match, so a group spelled `lint_tools` that is referenced as
`"lint-tools"` left a dangling entry behind and the project could no longer
be loaded ("Group 'ci' includes group 'lint-tools' which is not defined").
Canonicalize both sides, and remove the entry as it is actually spelled.
The PEP 735 `[dependency-groups]` branch is untouched.
037fcbe to
d2a178e
Compare
|
Thanks, pushed Comment 1 (dangling PEP 735
Comment 2 (a canonically equivalent group surviving under a differently spelled key) — not reachable. Such a project does not load at all, because both sections feed the same duplicate-name check: $ poetry check
The Poetry configuration is invalid:
- Duplicate dependency group name after normalization: lint-tools (lint-tools, lint_tools)So when |
chrikrah
left a comment
There was a problem hiding this comment.
@lau0708 the legacy-section fix holds up in my run below. 3843d7c also changes the [dependency-groups] comparison, which #11225 changes with the same canonicalize_name match and isinstance guard, so the two now conflict in remove.py.
# git archive 3843d7c (base 4acc75e), Python 3.12 venv, remove.py loaded from the export
$ python -m pytest -q -p no:randomly tests/console/commands/test_remove.py
# 3843d7c: 42 passed
# remove.py back at 4acc75e, tests kept: 2 failed, 40 passed (both new differently-spelled tests)
$ ruff check / ruff format --check on remove.py and test_remove.py (ruff 0.17.6): clean
$ mypy src/poetry/console/commands/remove.py tests/console/commands/test_remove.py (mypy 2.4.1): no issues
$ git merge-tree --write-tree 3843d7c ba0af77 # #11230 head vs #11225 head
CONFLICT (content): Merge conflict in src/poetry/console/commands/remove.py
# not run: Windows, the full tests/ suite
The description still says the PEP 735 branch is untouched and the hunks are disjoint. Would you drop that hunk and its test so both land in either order, or update the description if the overlap is intended?
Restores the boundary stated in the description: python-poetry#11225 already normalizes the `[dependency-groups]` include-group comparison with the same `canonicalize_name` match, so keeping that hunk here only made the two PRs conflict in remove.py. The legacy `include-groups` fix and its regression test are unchanged, so the two PRs can now land in either order.
|
Taking the first option: dropped the Your read is right, and it's my mistake — I took sourcery's comment 1 as in scope without noticing #11225 already does exactly that comparison. Duplicating it here bought nothing and cost the disjointness. The mixed-format case is covered once #11225 lands, in whichever order. At Red is attributable to the dangling reference and not to the removal itself — the control assertion on line 1087 ( Nothing else in the diff changed: The branch is |
Related: #11224 — this is the legacy-section half; #11225 covers the PEP 735 half.
Problem
poetry removedeletes a dependency group that became empty and then cleans up references to it in other groups (RemoveCommand._remove_references_to_group,src/poetry/console/commands/remove.py:219). Both branches compared group names literally, but PEP 735 says group names must be normalized before comparison, and Poetry normalizes them everywhere else (poetry-core's_configure_package_dependency_groupsdoescanonicalize_name()on both the group key and itsinclude-group/include-groupsentries). So a group key and a reference to it can legitimately differ in spelling.With this
pyproject.toml:poetry remove --group lint_tools six --lockexits 0 and drops thelint_toolsgroup, but leavesinclude-groups = ["lint-tools"]behind. The project is now unusable, and the failure surfaces on the next command:What changed
src/poetry/console/commands/remove.py, legacy[tool.poetry.group.<name>] include-groupsbranch only:canonicalize_name()of both sides instead of==;pyproject.toml(the stored name may differ from the--groupvalue), instead oflist.remove(group_name).The PEP 735
[dependency-groups]branch is deliberately untouched — that is #11225. The two hunks are disjoint, so they can land in either order; I'm happy to fold this into #11225 instead if you prefer a single PR.Out of scope:
--groupoption lookup itself (poetry_groups_content.get(group)), which is #11192 / #11193.Verification
Red on base (commit
037fcbe's parent), new testtest_remove_cleans_up_differently_spelled_legacy_include_group:Green on the branch, same test:
"lint_tools" not in content["tool"]["poetry"]["group"]). The red is therefore attributable to the dangling reference, not to the removal.pyproject.tomlwithFactory().create_poetry()and asserts the lock is fresh — that is the user-visible part: an unloadable project.tests/console:1004 passed, 6 skipped, 3 failed. The same 3 failures (env/test_info.py::test_env_info_displays_complete_info,debug/test_info.py::test_debug_info_displays_complete_info,test_init.py::test_empty_license) reproduce with identical counts on the clean base in this environment, so they are unrelated.pyproject.tomlkeepsci = { dependencies = { idna } }, and bothpoetry lockandpoetry show --only cisucceed.mypyclean on all 381 source files (same command the CI job runs), andruff check/ruff format --check(0.17.4, the pinned version) clean on both changed files.Checklist
AI assistance
Prepared with an AI coding assistant. The failing case, the red/green runs, the full-suite baseline comparison and the CLI reproduction above were all executed and verified locally.