Skip to content

Commit 03d92ed

Browse files
deepsource-autofix[bot]1minds3t
authored andcommitted
refactor: refactor unnecessary else / elif when if block has a continue statement
The use of `else` or `elif` becomes redundant and can be dropped if the last statement under the leading `if` / `elif` block is a `continue` statement. In the case of an `elif` after `continue`, it can be written as a separate `if` block. For `else` blocks after `continue`, the statements can be shifted out of `else`. Please refer to the examples below for reference. Refactoring the code this way can improve code-readability and make it easier to maintain.
1 parent a1cd3b7 commit 03d92ed

4 files changed

Lines changed: 22 additions & 28 deletions

File tree

src/omnipkg/core.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ def run_verbose(cmd: List[str], error_msg: str):
12351235
)
12361236
filtered_deps.append("safety>=2.0.0,<3.0")
12371237
continue
1238-
elif major == 3 and minor >= 15:
1238+
if major == 3 and minor >= 15:
12391239
# Python 3.15+: skip safety (pydantic-core doesn't support it yet)
12401240
safe_print(
12411241
_(" ⏭️ Skipping {} (pydantic-core not yet compatible with Python 3.15+)").format(dep)
@@ -12062,13 +12062,12 @@ def smart_install(
1206212062
)
1206312063
fully_resolved_specs.append(resolved_spec)
1206412064
continue
12065-
elif install_strategy == "stable-main":
12065+
if install_strategy == "stable-main":
1206612066
safe_print(_(' ✓ {} [satisfied: {} - bubble @ {}]').format(resolved_spec, duration_str, bubble_path))
1206712067
fully_resolved_specs.append(resolved_spec)
1206812068
continue
12069-
else:
12070-
needs_installation.append(resolved_spec)
12071-
continue
12069+
needs_installation.append(resolved_spec)
12070+
continue
1207212071
else:
1207312072
needs_installation.append(resolved_spec)
1207412073

@@ -12227,10 +12226,10 @@ def smart_install(
1222712226
if install_status == "active":
1222812227
safe_print(_('✅ {} already satisfied (active in main env)').format(pkg_spec))
1222912228
continue
12230-
elif install_status == "bubble" and install_strategy == "stable-main":
12229+
if install_status == "bubble" and install_strategy == "stable-main":
1223112230
safe_print(f"✅ {pkg_spec} already satisfied (found as bubble)")
1223212231
continue
12233-
elif install_status == "bubble" and install_strategy == "latest-active":
12232+
if install_status == "bubble" and install_strategy == "latest-active":
1223412233
# Bubble exists but we need it in main env - NOT satisfied
1223512234
is_satisfied = False
1223612235
break
@@ -12277,18 +12276,17 @@ def smart_install(
1227712276
processed_packages.append(pkg_spec)
1227812277
continue
1227912278

12280-
elif install_status == "bubble":
12279+
if install_status == "bubble":
1228112280
# If found in a bubble, satisfaction DEPENDS on the install strategy.
1228212281
if install_strategy == "stable-main":
1228312282
# For stable-main, a bubble is good enough.
1228412283
safe_print(f"✅ {pkg_spec} already satisfied (found as bubble)")
1228512284
processed_packages.append(pkg_spec)
1228612285
continue
12287-
else:
12288-
# For 'latest-active', a bubble is NOT good enough. We need to install.
12289-
# Mark as not satisfied and stop checking. The main installer will handle it.
12290-
all_packages_satisfied = False
12291-
break # Exit the loop immediately
12286+
# For 'latest-active', a bubble is NOT good enough. We need to install.
12287+
# Mark as not satisfied and stop checking. The main installer will handle it.
12288+
all_packages_satisfied = False
12289+
break # Exit the loop immediately
1229212290

1229312291
elif install_status is None:
1229412292
# Not found in main env or as a bubble. Might be nested, so check the KB.

src/omnipkg/installation/smart_install.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,14 @@ def install(
346346
fully_resolved_specs.append(resolved_spec)
347347
resolved_package_cache[pkg_spec] = resolved_spec
348348
continue
349-
elif install_strategy == "stable-main":
349+
if install_strategy == "stable-main":
350350
self._safe_print(f" ✓ {resolved_spec} [satisfied: {duration_str} - bubble]")
351351
fully_resolved_specs.append(resolved_spec)
352352
resolved_package_cache[pkg_spec] = resolved_spec
353353
continue
354-
else:
355-
needs_installation.append(resolved_spec)
356-
resolved_package_cache[pkg_spec] = resolved_spec
357-
continue
354+
needs_installation.append(resolved_spec)
355+
resolved_package_cache[pkg_spec] = resolved_spec
356+
continue
358357
else:
359358
needs_installation.append(resolved_spec)
360359
resolved_package_cache[pkg_spec] = resolved_spec
@@ -385,7 +384,7 @@ def install(
385384
validated_specs.append(spec)
386385
self._safe_print(f" ✓ Disk-validated '{spec}' (skipping pip)")
387386
continue
388-
elif _bubble_path.exists():
387+
if _bubble_path.exists():
389388
resolved_package_cache[spec] = spec
390389
validated_specs.append(spec)
391390
self._safe_print(f" ✓ Disk-validated '{spec}' (skipping pip)")

src/omnipkg/isolation/worker_daemon.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5900,12 +5900,10 @@ def _send(self, req):
59005900
attempts = 0
59015901
self.auto_start = False
59025902
continue
5903-
else:
5904-
return {
5905-
"success": False,
5906-
"error": "Failed to auto-start daemon (timeout)",
5907-
}
5908-
5903+
return {
5904+
"success": False,
5905+
"error": "Failed to auto-start daemon (timeout)",
5906+
}
59095907
except Exception as e:
59105908
return {"success": False, "error": _('Communication error: {}').format(e)}
59115909

src/omnipkg/package_meta_builder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,9 +1000,8 @@ def _discover_distributions_fast(
10001000
if _dbg:
10011001
print(f"[FAST-DISC] P1: ✅ found via known path", flush=True)
10021002
continue
1003-
else:
1004-
if _dbg:
1005-
print(f"[FAST-DISC] P1: version mismatch {dist.version} != {version}", flush=True)
1003+
if _dbg:
1004+
print(f"[FAST-DISC] P1: version mismatch {dist.version} != {version}", flush=True)
10061005
except Exception as e:
10071006
if _dbg:
10081007
print(f"[FAST-DISC] P1: PathDistribution failed: {e}", flush=True)

0 commit comments

Comments
 (0)