Skip to content

fix: Poetry single-component tilde constraint converts to an invalid specifier - #3852

Closed
VXNCXNX wants to merge 2 commits into
pdm-project:mainfrom
VXNCXNX:fix/poetry-single-component-tilde
Closed

fix: Poetry single-component tilde constraint converts to an invalid specifier#3852
VXNCXNX wants to merge 2 commits into
pdm-project:mainfrom
VXNCXNX:fix/poetry-single-component-tilde

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

pdm import -f poetry crashes on a single-component tilde constraint such as foo = "~1". It is converted to ~=1, which is not a valid PEP 440 specifier:

before   pdm.formats.base.MetaConvertError:
         dependencies: Invalid specifier for foo: ~=1: Invalid specifier: '~=1'

after    dependencies = [
             "foo<2,>=1",
             "bar~=2.5",
             "baz~=1.2.3",
         ]

Poetry defines ~1 as >=1.0.0,<2.0.0, so the single-component case reuses _caret_upper_bound, which gives the same bound for this shape. Multi-component tilde keeps mapping to ~=, so ~2.5 and ~1.2.3 are untouched.

Follow-up to #3848, which fixed the caret branch and left this one. Test added in tests/test_formats.py; removing the branch brings back Invalid specifier: '~=1'. tests/test_formats.py passes apart from test_export_from_pylock_not_empty, which fails identically on an unmodified checkout. ruff check and format clean.

AI disclosure: written with Claude Code. I ran pdm import before and after and checked the mutation myself.

@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 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.49%. Comparing base (bc67b54) to head (79ddb34).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3852   +/-   ##
=======================================
  Coverage   88.49%   88.49%           
=======================================
  Files         121      121           
  Lines       13276    13279    +3     
  Branches     2255     2256    +1     
=======================================
+ Hits        11748    11751    +3     
  Misses        962      962           
  Partials      566      566           
Flag Coverage Δ
unittests 88.38% <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.

Comment thread src/pdm/formats/poetry.py
if "." not in ver:
# ``~=1`` is not a valid PEP 440 specifier, and Poetry's ``~1``
# allows the minor version to change, so it means ``>=1,<2``.
parts.append(f">={ver},<{_caret_upper_bound(ver)}")

@frostming frostming Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about changing to ~=1.0, i think they are equivalent

@frostming frostming closed this Aug 27, 2026
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