Skip to content

Commit

Permalink
special case union of single marker with inverse
Browse files Browse the repository at this point in the history
To avoid ending up with constraints like:

bar==7.8.9; platform_system != 'Windows' or platform_system == 'Windows'
  • Loading branch information
dimbleby authored and neersighted committed Jan 27, 2022
1 parent 587654c commit c86c602
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ def union(self, other: MarkerTypes) -> MarkerTypes:
if self == other:
return self

if self == other.invert():
return AnyMarker()

return MarkerUnion.of(self, other)

return other.union(self)
Expand Down
6 changes: 6 additions & 0 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ def test_single_marker_union_with_union_duplicate():
assert str(union) == 'sys_platform == "darwin" or python_version <= "3.6"'


def test_single_marker_union_with_inverse():
m = parse_marker('sys_platform == "darwin"')
union = m.union(parse_marker('sys_platform != "darwin"'))
assert union.is_any()


def test_multi_marker():
m = parse_marker('sys_platform == "darwin" and implementation_name == "cpython"')

Expand Down

0 comments on commit c86c602

Please sign in to comment.