Skip to content

Commit 888fe35

Browse files
committed
fix: improve docstrings and format
Signed-off-by: Frost Ming <me@frostming.com>
1 parent 18bb588 commit 888fe35

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

src/dep_logic/markers/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ def __or__(self, other: Any) -> BaseMarker:
2424
raise NotImplementedError
2525

2626
def is_any(self) -> bool:
27+
"""Returns True if the marker allows any environment."""
2728
return False
2829

2930
def is_empty(self) -> bool:
31+
"""Returns True if the marker disallows any environment."""
3032
return False
3133

3234
@abstractmethod
@@ -35,18 +37,28 @@ def evaluate(
3537
environment: dict[str, str | set[str]] | None = None,
3638
context: EvaluationContext = "metadata",
3739
) -> bool:
40+
"""Evaluates the marker against the given environment.
41+
42+
Args:
43+
environment: The environment to evaluate against.
44+
context: The context in which the evaluation is performed,
45+
can be "lock_file", "metadata", or "requirement".
46+
"""
3847
raise NotImplementedError
3948

4049
@abstractmethod
4150
def without_extras(self) -> BaseMarker:
51+
"""Generate a new marker from the current marker but without "extra" markers."""
4252
raise NotImplementedError
4353

4454
@abstractmethod
4555
def exclude(self, marker_name: str) -> BaseMarker:
56+
"""Generate a new marker from the current marker but without the given marker."""
4657
raise NotImplementedError
4758

4859
@abstractmethod
4960
def only(self, *marker_names: str) -> BaseMarker:
61+
"""Generate a new marker from the current marker but only with the given markers."""
5062
raise NotImplementedError
5163

5264
def __repr__(self) -> str:

src/dep_logic/specifiers/range.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __str__(self) -> str:
8181
simplified = self._simplified_form
8282
if simplified is not None:
8383
return simplified
84-
return f'{">=" if self.include_min else ">"}{self.min},{"<=" if self.include_max else "<"}{self.max}'
84+
return f"{'>=' if self.include_min else '>'}{self.min},{'<=' if self.include_max else '<'}{self.max}"
8585

8686
def contains(
8787
self, version: UnparsedVersion, prereleases: bool | None = None
@@ -115,11 +115,8 @@ def allows_lower(self, other: RangeSpecifier) -> bool:
115115
if self.min is None:
116116
return True
117117

118-
return (
119-
self.min < other.min
120-
or self.min == other.min
121-
and self.include_min
122-
and not other.include_min
118+
return self.min < other.min or (
119+
self.min == other.min and self.include_min and not other.include_min
123120
)
124121

125122
def allows_higher(self, other: RangeSpecifier) -> bool:
@@ -128,11 +125,8 @@ def allows_higher(self, other: RangeSpecifier) -> bool:
128125
if self.max is None:
129126
return True
130127

131-
return (
132-
self.max > other.max
133-
or self.max == other.max
134-
and self.include_max
135-
and not other.include_max
128+
return self.max > other.max or (
129+
self.max == other.max and self.include_max and not other.include_max
136130
)
137131

138132
def is_strictly_lower(self, other: RangeSpecifier) -> bool:
@@ -142,10 +136,8 @@ def is_strictly_lower(self, other: RangeSpecifier) -> bool:
142136
if self.max is None or other.min is None:
143137
return False
144138

145-
return (
146-
self.max < other.min
147-
or self.max == other.min
148-
and False in (self.include_max, other.include_min)
139+
return self.max < other.min or (
140+
self.max == other.min and False in (self.include_max, other.include_min)
149141
)
150142

151143
def is_adjacent_to(self, other: RangeSpecifier) -> bool:
@@ -162,22 +154,24 @@ def __lt__(self, other: Any) -> bool:
162154
return self.allows_lower(other)
163155

164156
def is_superset(self, other: RangeSpecifier) -> bool:
165-
min_lower = (
166-
self.min is None
167-
or other.min is not None
157+
min_lower = self.min is None or (
158+
other.min is not None
168159
and (
169160
self.min < other.min
170-
or self.min == other.min
171-
and not (not self.include_min and other.include_min)
161+
or (
162+
self.min == other.min
163+
and not (not self.include_min and other.include_min)
164+
)
172165
)
173166
)
174-
max_higher = (
175-
self.max is None
176-
or other.max is not None
167+
max_higher = self.max is None or (
168+
other.max is not None
177169
and (
178170
self.max > other.max
179-
or self.max == other.max
180-
and not (not self.include_max and other.include_max)
171+
or (
172+
self.max == other.max
173+
and not (not self.include_max and other.include_max)
174+
)
181175
)
182176
)
183177
return min_lower and max_higher

0 commit comments

Comments
 (0)