Skip to content

Commit 2676413

Browse files
committed
markers: recognize empty python_version markers
Without this fix, the intersection of `python_version > "3.8"` and `python_version < "3.9"` is not detected as empty marker.
1 parent 5209a79 commit 2676413

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

src/poetry/core/version/markers.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,12 +1219,20 @@ def _merge_single_markers(
12191219
elif marker1.name == "python_version":
12201220
from poetry.core.packages.utils.utils import get_python_constraint_from_marker
12211221

1222-
if isinstance(result_constraint, VersionRange) and result_constraint.min:
1223-
# Convert 'python_version >= "3.8" and python_version < "3.9"'
1224-
# to 'python_version == "3.8"'
1225-
candidate = parse_marker(f'{marker1.name} == "{result_constraint.min}"')
1226-
if get_python_constraint_from_marker(candidate) == result_constraint:
1227-
result_marker = candidate
1222+
if isinstance(result_constraint, VersionRange) and merge_class == MultiMarker:
1223+
if result_constraint.min:
1224+
# Convert 'python_version >= "3.8" and python_version < "3.9"'
1225+
# to 'python_version == "3.8"'.
1226+
candidate = parse_marker(f'{marker1.name} == "{result_constraint.min}"')
1227+
if get_python_constraint_from_marker(candidate) == result_constraint:
1228+
result_marker = candidate
1229+
if result_marker is None:
1230+
# Detect 'python_version > "3.8" and python_version < "3.9"' as empty.
1231+
result_constraint = get_python_constraint_from_marker(
1232+
marker1
1233+
).intersect(get_python_constraint_from_marker(marker2))
1234+
if result_constraint.is_empty():
1235+
result_marker = EmptyMarker()
12281236

12291237
elif isinstance(result_constraint, VersionUnion) and merge_class == MarkerUnion:
12301238
# Convert 'python_version == "3.8" or python_version >= "3.9"'

tests/version/test_markers.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ def test_single_marker_intersect() -> None:
171171
assert str(intersection) == 'python_version >= "3.4" and python_version < "3.6"'
172172

173173

174+
@pytest.mark.parametrize(
175+
("marker1", "marker2"),
176+
[
177+
('sys_platform == "win32"', 'sys_platform == "linux"'),
178+
('sys_platform != "win32"', 'sys_platform == "win32"'),
179+
('python_version >= "3.6"', 'python_version < "3.6"'),
180+
('python_version == "3.6"', 'python_version == "3.7"'),
181+
('python_version > "3.6"', 'python_version <= "3.6"'),
182+
('python_version >= "3.6"', 'python_version < "3.6"'),
183+
('python_version > "3.6"', 'python_version < "3.7"'),
184+
],
185+
)
186+
def test_single_marker_intersect_is_empty(marker1: str, marker2: str) -> None:
187+
assert parse_marker(marker1).intersect(parse_marker(marker2)).is_empty()
188+
189+
174190
@pytest.mark.parametrize(
175191
("marker1", "marker2", "expected"),
176192
[
@@ -852,11 +868,6 @@ def test_multi_marker_union_multi_is_multi(
852868
'python_version >= "3.6" and python_version < "3.8"',
853869
'python_version >= "3.6" and python_version < "3.8"',
854870
),
855-
(
856-
'python_version > "3.6" and python_full_version < "3.6.2"',
857-
'python_version > "3.6" and python_version < "3.7"',
858-
'python_version > "3.6" and python_version < "3.7"',
859-
),
860871
(
861872
'python_version > "3.6" and python_full_version < "3.7.2"',
862873
'python_version > "3.6" and python_version < "3.8"',
@@ -2260,16 +2271,16 @@ def test_intersection_no_endless_recursion() -> None:
22602271
' and extra != "postgis"'
22612272
)
22622273
m2 = parse_marker(
2263-
'python_version > "3.12" and python_version < "3.13" or extra != "databricks"'
2274+
'python_version >= "3.12" and python_version < "3.13" or extra != "databricks"'
22642275
)
22652276
expected = (
22662277
'(python_version < "3.9" or extra != "bigquery" and extra != "parquet"'
22672278
' and extra != "motherduck" and extra != "athena" and extra != "synapse"'
22682279
' and extra != "clickhouse" and extra != "dremio" and extra != "lancedb"'
22692280
' and extra != "deltalake" and extra != "pyiceberg")'
22702281
' and python_version < "3.13" and extra != "postgres" and extra != "redshift"'
2271-
' and extra != "postgis" and (python_version > "3.12"'
2272-
' and python_version < "3.13" or extra != "databricks")'
2282+
' and extra != "postgis"'
2283+
' and (python_version == "3.12" or extra != "databricks")'
22732284
)
22742285
assert str(m1.intersect(m2)) == expected
22752286

0 commit comments

Comments
 (0)