Skip to content

fix reduce_by_python_constraint for marker unions #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", ""),
Copy link
Member Author

Choose a reason for hiding this comment

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

I just changed this test because there is a duplicate of the original test some lines below.

('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"',
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed these test because with the fix they are not that intesting anymore because they are too similar to the test above.

),
(
'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
Loading