Skip to content

fix: Poetry caret on a 0.x version converts to the wrong upper bound - #3848

Merged
frostming merged 1 commit into
pdm-project:mainfrom
VXNCXNX:fix/poetry-caret-zero-major
Aug 17, 2026
Merged

fix: Poetry caret on a 0.x version converts to the wrong upper bound#3848
frostming merged 1 commit into
pdm-project:mainfrom
VXNCXNX:fix/poetry-caret-zero-major

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What's broken

pdm import -f poetry converts every caret constraint by bumping the major component, so a 0.x caret gets a far wider bound than Poetry means. The imported project then accepts releases Poetry would have refused.

Repro

attrs = "^0.2.3", tinylib = "^0.0.3", requests = "^2.28.1" in a Poetry project:

before:
dependencies = ["attrs<1.0.0,>=0.2.3", "tinylib<1.0.0,>=0.0.3", "requests<3.0.0,>=2.28.1"]

after:
dependencies = ["attrs<0.3.0,>=0.2.3", "tinylib<0.0.4,>=0.0.3", "requests<3.0.0,>=2.28.1"]

The fix

A caret allows changes that do not modify the leftmost non-zero component, so the bumped position depends on where that component is. _caret_upper_bound finds it instead of assuming the major.

Verification

test_convert_poetry_caret_constraint is parametrised over all seven rows of Poetry's own caret table, ^1.2.3 through ^0, checked against the table in their dependency-specification docs. Forcing the index back to 0 fails three of them with assertion errors.

Two assertions in test_convert_poetry had the old bounds baked in, cleo<1.0.0 for ^0.7.6 and cachecontrol<1.0.0 for ^0.12.4. Both fixture constraints are 0.x, so those were asserting the bug; they now read <0.8.0 and <0.13.0.

tests/test_formats.py passes, 53 tests. The wider run has one failure, test_create_venv_in_project[venv-True], identical on a clean checkout here because this box has no ensurepip. ruff check and ruff format --check clean.

A caret requirement allows changes that do not modify the leftmost
non-zero component, so ^0.2.3 means <0.3.0 and ^0.0.3 means <0.0.4.
The importer always bumped the major, widening both to <1.0.0 and
letting an import pull in a breaking release.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.43%. Comparing base (29c40ea) to head (a58848d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3848      +/-   ##
==========================================
+ Coverage   88.41%   88.43%   +0.01%     
==========================================
  Files         121      121              
  Lines       13258    13262       +4     
  Branches     2252     2252              
==========================================
+ Hits        11722    11728       +6     
+ Misses        966      965       -1     
+ Partials      570      569       -1     
Flag Coverage Δ
unittests 88.32% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@frostming
frostming merged commit 95a7777 into pdm-project:main Aug 17, 2026
25 checks passed
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.

2 participants