Skip to content

Commit cacc856

Browse files
committed
improve reduce_by_python_constraint
1 parent eee84d7 commit cacc856

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/poetry/core/version/markers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ def reduce_by_python_constraint(
456456
self, python_constraint: VersionConstraint
457457
) -> BaseMarker:
458458
if self.name in PYTHON_VERSION_MARKERS:
459+
from poetry.core.packages.utils.utils import create_nested_marker
459460
from poetry.core.packages.utils.utils import (
460461
get_python_constraint_from_marker,
461462
)
@@ -467,6 +468,13 @@ def reduce_by_python_constraint(
467468
elif not constraint.allows_any(python_constraint):
468469
return EmptyMarker()
469470

471+
python_marker = parse_marker(
472+
create_nested_marker("python_version", python_constraint)
473+
)
474+
intersection = self.intersect(python_marker)
475+
if isinstance(intersection, SingleMarker):
476+
return intersection
477+
470478
return self
471479

472480
def invert(self) -> BaseMarker:

tests/version/test_markers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,11 @@ def test_only(marker: str, only: list[str], expected: str) -> None:
14951495
('python_version > "3.8"', "~3.8", "<empty>"),
14961496
('python_version >= "3.8"', "~3.8", ""),
14971497
('python_version >= "3.9"', "~3.8", "<empty>"),
1498+
('python_version == "3.9"', ">=3.9", 'python_version == "3.9"'),
1499+
('python_version <= "3.9"', ">=3.9", 'python_version == "3.9"'),
1500+
('python_version < "3.10"', ">=3.9", 'python_version == "3.9"'),
1501+
('python_version <= "3.10"', ">=3.9", 'python_version <= "3.10"'),
1502+
('python_version < "3.11"', ">=3.9", 'python_version < "3.11"'),
14981503
('python_full_version >= "3.8.0"', "~3.8", ""),
14991504
('python_full_version >= "3.8.1"', "~3.8", 'python_full_version >= "3.8.1"'),
15001505
('python_full_version < "3.8.0"', "~3.8", "<empty>"),
@@ -1519,7 +1524,7 @@ def test_only(marker: str, only: list[str], expected: str) -> None:
15191524
(
15201525
'python_version < "3.8" or python_version >= "3.9"',
15211526
">=3.7",
1522-
'python_version < "3.8" or python_version >= "3.9"',
1527+
'python_version == "3.7" or python_version >= "3.9"',
15231528
),
15241529
('python_version < "3.8" or python_version >= "3.9"', "~3.7", ""),
15251530
(
@@ -1539,7 +1544,7 @@ def test_only(marker: str, only: list[str], expected: str) -> None:
15391544
(
15401545
'python_version < "3.8" or python_version >= "3.9"',
15411546
"~3.6 || ~3.8",
1542-
'python_version < "3.8"',
1547+
'python_version == "3.6"',
15431548
),
15441549
(
15451550
(

0 commit comments

Comments
 (0)