Skip to content

Commit 2a9941a

Browse files
committed
chore: adding ruff RET
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 7e1b968 commit 2a9941a

File tree

7 files changed

+40
-48
lines changed

7 files changed

+40
-48
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extend-select = [
113113
"PT", # flake8-pytest-style
114114
"PYI", # flake8-pyi
115115
"Q", # flake8-quotes
116+
"RET", # flake8-return
116117
"RSE", # flake8-raise
117118
"RUF", # Ruff-specific rules
118119
"SIM", # flake8-simplify

src/packaging/_parser.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,25 +310,21 @@ def _parse_marker_item(tokenizer: Tokenizer) -> MarkerItem:
310310
return (marker_var_left, marker_op, marker_var_right)
311311

312312

313-
def _parse_marker_var(tokenizer: Tokenizer) -> MarkerVar:
313+
def _parse_marker_var(tokenizer: Tokenizer) -> MarkerVar: # noqa: RET503
314314
"""
315315
marker_var = VARIABLE | QUOTED_STRING
316316
"""
317317
if tokenizer.check("VARIABLE"):
318318
return process_env_var(tokenizer.read().text.replace(".", "_"))
319-
elif tokenizer.check("QUOTED_STRING"):
319+
if tokenizer.check("QUOTED_STRING"):
320320
return process_python_str(tokenizer.read().text)
321-
else:
322-
tokenizer.raise_syntax_error(
323-
message="Expected a marker variable or quoted string"
324-
)
321+
tokenizer.raise_syntax_error(message="Expected a marker variable or quoted string")
325322

326323

327324
def process_env_var(env_var: str) -> Variable:
328325
if env_var in ("platform_python_implementation", "python_implementation"):
329326
return Variable("platform_python_implementation")
330-
else:
331-
return Variable(env_var)
327+
return Variable(env_var)
332328

333329

334330
def process_python_str(python_str: str) -> Value:
@@ -343,14 +339,13 @@ def _parse_marker_op(tokenizer: Tokenizer) -> Op:
343339
if tokenizer.check("IN"):
344340
tokenizer.read()
345341
return Op("in")
346-
elif tokenizer.check("NOT"):
342+
if tokenizer.check("NOT"):
347343
tokenizer.read()
348344
tokenizer.expect("WS", expected="whitespace after 'not'")
349345
tokenizer.expect("IN", expected="'in' after 'not'")
350346
return Op("not in")
351-
elif tokenizer.check("OP"):
347+
if tokenizer.check("OP"):
352348
return Op(tokenizer.read().text)
353-
else:
354-
return tokenizer.raise_syntax_error(
355-
"Expected marker operator, one of <=, <, !=, ==, >=, >, ~=, ===, in, not in"
356-
)
349+
return tokenizer.raise_syntax_error(
350+
"Expected marker operator, one of <=, <, !=, ==, >=, >, ~=, ===, in, not in"
351+
)

src/packaging/markers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,10 @@ def _format_marker(
157157
inner = (_format_marker(m, first=False) for m in marker)
158158
if first:
159159
return " ".join(inner)
160-
else:
161-
return "(" + " ".join(inner) + ")"
162-
elif isinstance(marker, tuple):
160+
return "(" + " ".join(inner) + ")"
161+
if isinstance(marker, tuple):
163162
return " ".join([m.serialize() for m in marker])
164-
else:
165-
return marker
163+
return marker
166164

167165

168166
_operators: dict[str, Operator] = {
@@ -204,10 +202,12 @@ def _normalize(
204202
assert isinstance(rhs, str), "extra value must be a string"
205203
return (canonicalize_name(lhs), canonicalize_name(rhs))
206204
if key in MARKERS_ALLOWING_SET:
207-
if isinstance(rhs, str): # pragma: no cover
208-
return (canonicalize_name(lhs), canonicalize_name(rhs))
209-
else:
210-
return (canonicalize_name(lhs), {canonicalize_name(v) for v in rhs})
205+
return (
206+
canonicalize_name(lhs),
207+
canonicalize_name(rhs)
208+
if isinstance(rhs, str)
209+
else {canonicalize_name(v) for v in rhs},
210+
)
211211

212212
# other environment markers don't have such standards
213213
return lhs, rhs

src/packaging/metadata.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,12 @@ def _get_payload(msg: email.message.Message, source: bytes | str) -> str:
236236
return payload
237237
# If our source is a bytes, then we're managing the encoding and we need
238238
# to deal with it.
239-
else:
240-
bpayload = msg.get_payload(decode=True)
241-
assert isinstance(bpayload, bytes)
242-
try:
243-
return bpayload.decode("utf8", "strict")
244-
except UnicodeDecodeError as exc:
245-
raise ValueError("payload in an invalid encoding") from exc
239+
bpayload = msg.get_payload(decode=True)
240+
assert isinstance(bpayload, bytes)
241+
try:
242+
return bpayload.decode("utf8", "strict")
243+
except UnicodeDecodeError as exc:
244+
raise ValueError("payload in an invalid encoding") from exc
246245

247246

248247
# The various parse_FORMAT functions here are intended to be as lenient as
@@ -658,7 +657,7 @@ def _process_dynamic(self, value: list[str]) -> list[str]:
658657
raise self._invalid_metadata(
659658
f"{dynamic_field!r} is not allowed as a dynamic field"
660659
)
661-
elif dynamic_field not in _EMAIL_TO_RAW_MAPPING:
660+
if dynamic_field not in _EMAIL_TO_RAW_MAPPING:
662661
raise self._invalid_metadata(
663662
f"{dynamic_field!r} is not a valid dynamic field"
664663
)
@@ -746,7 +745,7 @@ def _process_import_names(self, value: list[str]) -> list[str]:
746745
f"{name!r} is invalid for {{field}}; "
747746
f"{identifier!r} is not a valid identifier"
748747
)
749-
elif keyword.iskeyword(identifier):
748+
if keyword.iskeyword(identifier):
750749
raise self._invalid_metadata(
751750
f"{name!r} is invalid for {{field}}; "
752751
f"{identifier!r} is a keyword"

src/packaging/specifiers.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,16 @@ def _compare_equal(self, prospective: Version, spec: str) -> bool:
419419
shortened_prospective = padded_prospective[: len(split_spec)]
420420

421421
return shortened_prospective == split_spec
422-
else:
423-
# Convert our spec string into a Version
424-
spec_version = Version(spec)
422+
# Convert our spec string into a Version
423+
spec_version = Version(spec)
425424

426-
# If the specifier does not have a local segment, then we want to
427-
# act as if the prospective version also does not have a local
428-
# segment.
429-
if not spec_version.local:
430-
prospective = Version(prospective.public)
425+
# If the specifier does not have a local segment, then we want to
426+
# act as if the prospective version also does not have a local
427+
# segment.
428+
if not spec_version.local:
429+
prospective = Version(prospective.public)
431430

432-
return prospective == spec_version
431+
return prospective == spec_version
433432

434433
def _compare_not_equal(self, prospective: Version, spec: str) -> bool:
435434
return not self._compare_equal(prospective, spec)

src/packaging/tags.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,13 @@ def platform_tags() -> Iterator[str]:
595595
"""
596596
if platform.system() == "Darwin":
597597
return mac_platforms()
598-
elif platform.system() == "iOS":
598+
if platform.system() == "iOS":
599599
return ios_platforms()
600-
elif platform.system() == "Android":
600+
if platform.system() == "Android":
601601
return android_platforms()
602-
elif platform.system() == "Linux":
602+
if platform.system() == "Linux":
603603
return _linux_platforms()
604-
else:
605-
return _generic_platforms()
604+
return _generic_platforms()
606605

607606

608607
def interpreter_name() -> str:

src/packaging/version.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ def local(self) -> str | None:
333333
"""
334334
if self._version.local:
335335
return ".".join(str(x) for x in self._version.local)
336-
else:
337-
return None
336+
return None
338337

339338
@property
340339
def public(self) -> str:

0 commit comments

Comments
 (0)