Skip to content

Commit

Permalink
Find another marker simplification at intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and neersighted committed May 29, 2022
1 parent 31d518d commit dfd1b39
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,14 @@ def of(cls, *markers: BaseMarker) -> BaseMarker:
intersected = True
elif constraint_intersection.is_empty():
return EmptyMarker()
elif (
isinstance(constraint_intersection, VersionConstraint)
and constraint_intersection.is_simple()
):
new_markers[i] = SingleMarker(
mark.name, constraint_intersection
)
intersected = True
elif isinstance(mark, MarkerUnion):
intersection = mark.intersect(marker)
if isinstance(intersection, SingleMarker):
Expand Down
13 changes: 13 additions & 0 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,16 @@ def test_union_should_drop_markers_if_their_complement_is_present(
)
def test_dnf(scheme: str, marker: BaseMarker, expected: BaseMarker) -> None:
assert dnf(marker) == expected


def test_single_markers_are_found_in_complex_intersection() -> None:
m1 = parse_marker('implementation_name != "pypy" and python_version <= "3.6"')
m2 = parse_marker(
'python_version >= "3.6" and python_version < "4.0" and implementation_name =='
' "cpython"'
)
intersection = m1.intersect(m2)
assert (
str(intersection)
== 'implementation_name == "cpython" and python_version == "3.6"'
)

0 comments on commit dfd1b39

Please sign in to comment.