Skip to content

Commit

Permalink
fix reduce_by_python_constraint for marker unions (#846)
Browse files Browse the repository at this point in the history
E.g. if the python constraint is `>=3.9`, reducing `python_version >= "3.8" or sys_platform == "linux"` should result in `AnyMarker` (not `sys_platform == "linux"`).
  • Loading branch information
radoering authored Mar 5, 2025
1 parent ab81345 commit 5209a79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,7 @@ def reduce_by_python_constraint(
if get_python_constraint_from_marker(
self.of(*python_only_markers)
).allows_all(python_constraint):
if not other_markers:
return AnyMarker()
markers = other_markers
return AnyMarker()

return self.of(
*(m.reduce_by_python_constraint(python_constraint) for m in markers)
Expand Down
22 changes: 11 additions & 11 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ def test_only(marker: str, only: list[str], expected: str) -> None:
("", "~3.8", ""),
("<empty>", "~3.8", "<empty>"),
('sys_platform == "linux"', "~3.8", 'sys_platform == "linux"'),
('python_version >= "3.8"', "~3.8", ""),
('python_version == "3.8"', "~3.8", ""),
('python_version == "3.8"', ">=3.8.7,<3.9.0", ""),
('python_version == "3.8" or python_version >= "3.9"', ">=3.8.0,<4.0.0", ""),
('python_version == "3.8" or python_version >= "3.9"', ">=3.8.7,<4.0.0", ""),
Expand Down Expand Up @@ -1552,6 +1552,11 @@ def test_only(marker: str, only: list[str], expected: str) -> None:
"<=3.10",
'python_version < "3.8" or python_version >= "3.9"',
),
(
'python_version == "3.8" or sys_platform == "linux"',
"~3.8",
"",
),
(
(
'python_version < "3.8"'
Expand All @@ -1572,25 +1577,20 @@ def test_only(marker: str, only: list[str], expected: str) -> None:
' or python_version >= "3.9"'
),
"~3.7 || ~3.9",
'sys_platform == "linux"',
"",
),
(
(
'python_version < "3.8" or sys_platform == "linux"'
' or python_version >= "3.9" or sys_platform == "win32"'
),
"~3.7 || ~3.9",
'sys_platform == "linux" or sys_platform == "win32"',
),
(
'python_version == "3.8" or sys_platform == "linux" or python_version >= "3.9"',
">=3.8.0,<4.0.0",
'sys_platform == "linux"',
"",
),
(
'python_version == "3.8" or sys_platform == "linux" or python_version >= "3.9"',
">=3.8.7,<4.0.0",
'sys_platform == "linux"',
'(python_version == "3.8" or platform_system == "Linux") and sys_platform == "darwin"',
"~3.8",
'sys_platform == "darwin"',
),
],
)
Expand Down

0 comments on commit 5209a79

Please sign in to comment.