Skip to content
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

Marker fixes #380

Merged
merged 2 commits into from
May 29, 2022
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
10 changes: 9 additions & 1 deletion src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def invert(self) -> BaseMarker:
)

min_ = self._constraint.min
min_operator = ">=" if self._constraint.include_min else "<"
min_operator = ">=" if self._constraint.include_min else ">"
max_ = self._constraint.max
max_operator = "<=" if self._constraint.include_max else "<"

Expand Down 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"'
)